/********************************************************************* * @fn osalInitTasks * * @brief This function invokes the initialization function for each task. * * @param void * * @return none */ void osalInitTasks( void ) { uint8 taskID = 0; tasksEvents = (uint16 *)osal_mem_alloc( sizeof( uint16 ) * tasksCnt); osal_memset( tasksEvents, 0, (sizeof( uint16 ) * tasksCnt)); /* LL Task */ LL_Init( taskID++ ); /* Hal Task */ Hal_Init( taskID++ ); /* HCI Task */ HCI_Init( taskID++ ); #if defined ( OSAL_CBTIMER_NUM_TASKS ) /* Callback Timer Tasks */ osal_CbTimerInit( taskID ); taskID += OSAL_CBTIMER_NUM_TASKS; #endif /* GAP Task */ GAP_Init( taskID++ ); /* Profiles */ GAPRole_Init( taskID++ ); /* Application */ SimpleBLEBroadcaster_Init( taskID ); }
void osalInitTasks(void) { uint8 taskID = 0; tasksEvents = (uint16*)osal_mem_alloc(sizeof(uint16) * tasksCnt); osal_memset(tasksEvents, 0, (sizeof(uint16) * tasksCnt)); LL_Init(taskID++); Hal_Init(taskID++); HCI_Init(taskID++); #if defined (OSAL_CBTIMER_NUM_TASKS) osal_CbTimerInit(taskID); taskID += OSAL_CBTIMER_NUM_TASKS; #endif L2CAP_Init( taskID++ ); GAP_Init(taskID++); GATT_Init(taskID++); SM_Init(taskID++); GAPRole_Init(taskID++); GAPBondMgr_Init(taskID++); GATTServApp_Init(taskID++); RemotePeripheralInit(taskID); };
void bsp_init(void) { HAL_Init(); /* Configure the system clock */ BSP_SystemClock_Config(); /* Configure LED0 */ BSP_LED_Init(LED0); /*UART2 init*/ UART_Init(); HAL_Delay(1000); /*sensor layer init*/ #ifdef SENSOR_FIFO jsensor_sys_init(); #endif /* Initialize the BlueNRG SPI driver */ BNRG_SPI_Init(); /* Initialize the BlueNRG HCI */ HCI_Init(); /* Reset BlueNRG hardware */ BlueNRG_RST(); /* Enable Power Clock */ __HAL_RCC_PWR_CLK_ENABLE(); rtc_init(); }
/********************************************************************* * @fn osalInitTasks * * @brief This function invokes the initialization function for each task. * * @param void * * @return none */ void osalInitTasks( void ) { uint8 taskID = 0; tasksEvents = (uint16 *)osal_mem_alloc( sizeof( uint16 ) * tasksCnt); VOID osal_memset( tasksEvents, 0, (sizeof( uint16 ) * tasksCnt)); /* LL Task */ LL_Init( taskID++ ); /* Hal Task */ Hal_Init( taskID++ ); /* HCI Task */ HCI_Init( taskID++ ); #if defined ( OSAL_CBTIMER_NUM_TASKS ) /* Callback Timer Tasks */ osal_CbTimerInit( taskID ); taskID += OSAL_CBTIMER_NUM_TASKS; #endif /* L2CAP Task */ L2CAP_Init( taskID++ ); /* GAP Task */ GAP_Init( taskID++ ); /* SM Task */ SM_Init( taskID++ ); /* GATT Task */ GATT_Init( taskID++ ); #if !defined ( GATT_DB_OFF_CHIP ) /* GATT Server App Task */ GATTServApp_Init( taskID++ ); #if defined ( GATT_TEST ) /* GATT Test Task */ GATTTest_Init( taskID++ ); #endif #endif // GATT_DB_OFF_CHIP #if defined ( GAP_BOND_MGR ) GAPBondMgr_Init( taskID++ ); #endif /* HCI Extension GAP Task */ HCI_EXT_App_Init( taskID ); }
/********************************************************************* * @fn osalInitTasks * * @brief This function invokes the initialization function for each task. * * @param void * * @return none */ void osalInitTasks( void ) { uint8 taskID = 0; tasksEvents = (uint16 *)osal_mem_alloc( sizeof( uint16 ) * tasksCnt); osal_memset( tasksEvents, 0, (sizeof( uint16 ) * tasksCnt)); /* LL Task */ LL_Init( taskID++ ); /* Hal Task */ Hal_Init( taskID++ ); /* HCI Task */ HCI_Init( taskID++ ); #if defined ( OSAL_CBTIMER_NUM_TASKS ) /* Callback Timer Tasks */ osal_CbTimerInit( taskID ); taskID += OSAL_CBTIMER_NUM_TASKS; #endif /* L2CAP Task */ L2CAP_Init( taskID++ ); /* GAP Task */ GAP_Init( taskID++ ); /* GATT Task */ GATT_Init( taskID++ ); /* SM Task */ SM_Init( taskID++ ); /* Profiles */ GAPCentralRole_Init( taskID++ ); GAPBondMgr_Init( taskID++ ); /* Application */ #if defined ( ZIGBEE_APP ) Zigbee_Init( taskID++ ); #endif #if defined _XBEE_APP_ XBeeInit(taskID ++); Hidapp_Init( taskID ); #endif //SimpleBLEPeripheral_Init( taskID ); }
/********************************************************************* * @fn osalInitTasks * * @brief This function invokes the initialization function for each task. * * @param void * * @return none */ void osalInitTasks( void ) { ICall_EntityID entity; ICall_Semaphore sem; uint8 taskID = 0; uint8 i; tasksEvents = (uint16 *)osal_mem_alloc( sizeof( uint16 ) * tasksCnt); osal_memset( tasksEvents, 0, (sizeof( uint16 ) * tasksCnt)); /* LL Task */ LL_Init( taskID++ ); /* HCI Task */ HCI_Init( taskID++ ); #if defined ( OSAL_CBTIMER_NUM_TASKS ) /* Callback Timer Tasks */ osal_CbTimerInit( taskID ); taskID += OSAL_CBTIMER_NUM_TASKS; #endif /* GAP Task */ GAP_Init( taskID++ ); /* ICall BLE Dispatcher Task */ bleDispatch_Init( taskID ); // ICall enrollment /* Enroll the service that this stack represents */ ICall_enrollService(ICALL_SERVICE_CLASS_BLE, NULL, &entity, &sem); /* Enroll the obtained dispatcher entity and OSAL task ID of HCI Ext App * to OSAL so that OSAL can route the dispatcher message into * the appropriate OSAL task. */ osal_enroll_dispatchid(taskID, entity); /* Register all other OSAL tasks to use the registered dispatcher entity * ID as the source of dispatcher messages, even though the other OSAL * tasks didn't register themselves to receive messages from application. */ for (i = 0; i < taskID; i++) { osal_enroll_senderid(i, entity); } }
/********************************************************************* * @fn osalInitTasks * * @brief This function invokes the initialization function for each task. * * @param void * * @return none */ void osalInitTasks( void ) { uint8 taskID = 0; tasksEvents = (uint16 *)osal_mem_alloc( sizeof( uint16 ) * tasksCnt); osal_memset( tasksEvents, 0, (sizeof( uint16 ) * tasksCnt)); /* LL Task */ LL_Init( taskID++ ); /* Hal Task */ Hal_Init( taskID++ ); /* HCI Task */ HCI_Init( taskID++ ); #if defined ( OSAL_CBTIMER_NUM_TASKS ) /* Callback Timer Tasks */ osal_CbTimerInit( taskID ); taskID += OSAL_CBTIMER_NUM_TASKS; #endif /* L2CAP Task */ L2CAP_Init( taskID++ ); /* GAP Task */ GAP_Init( taskID++ ); /* GATT Task */ GATT_Init( taskID++ ); /* SM Task */ SM_Init( taskID++ ); /* Profiles */ GAPRole_Init( taskID++ ); GAPBondMgr_Init( taskID++ ); GATTServApp_Init( taskID++ ); HidDev_Init( taskID++ ); /* Application */ HidKbdMouse_Init( taskID ); }
/** * @brief Main function to show how to use the BlueNRG Bluetooth Low Energy * expansion board to send data from a Nucleo board to a smartphone * with the support BLE and the "BlueNRG" app freely available on both * GooglePlay and iTunes. * The URL to the iTunes for the "BlueNRG" app is * http://itunes.apple.com/app/bluenrg/id705873549?uo=5 * The URL to the GooglePlay is * https://play.google.com/store/apps/details?id=com.st.bluenrg * The source code of the "BlueNRG" app, both for iOS and Android, is * freely downloadable from the developer website at * http://software.g-maps.it/ * The board will act as Server-Peripheral. * * After connection has been established: * - by pressing the USER button on the board, the cube showed by * the app on the smartphone will rotate. * * The communication is done using a vendor specific profile. * * @param None * @retval None */ int main(void) { const char *name = "BlueNRG"; uint8_t SERVER_BDADDR[] = {0x12, 0x34, 0x00, 0xE1, 0x80, 0x03}; uint8_t bdaddr[BDADDR_SIZE]; uint16_t service_handle, dev_name_char_handle, appearance_char_handle; uint8_t hwVersion; uint16_t fwVersion; int ret; /* STM32Cube HAL library initialization: * - Configure the Flash prefetch, Flash preread and Buffer caches * - Systick timer is configured by default as source of time base, but user * can eventually implement his proper time base source (a general purpose * timer for example or other time source), keeping in mind that Time base * duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and * handled in milliseconds basis. * - Low Level Initialization */ HAL_Init(); #if NEW_SERVICES /* Configure LED2 */ BSP_LED_Init(LED2); #endif /* Configure the User Button in GPIO Mode */ BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_GPIO); /* Configure the system clock */ SystemClock_Config(); /* Initialize the BlueNRG SPI driver */ BNRG_SPI_Init(); /* Initialize the BlueNRG HCI */ HCI_Init(); /* Reset BlueNRG hardware */ BlueNRG_RST(); /* get the BlueNRG HW and FW versions */ getBlueNRGVersion(&hwVersion, &fwVersion); /* * Reset BlueNRG again otherwise we won't * be able to change its MAC address. * aci_hal_write_config_data() must be the first * command after reset otherwise it will fail. */ BlueNRG_RST(); PRINTF("HWver %d, FWver %d", hwVersion, fwVersion); if (hwVersion > 0x30) { /* X-NUCLEO-IDB05A1 expansion board is used */ bnrg_expansion_board = IDB05A1; /* * Change the MAC address to avoid issues with Android cache: * if different boards have the same MAC address, Android * applications unless you restart Bluetooth on tablet/phone */ SERVER_BDADDR[5] = 0x02; } /* The Nucleo board must be configured as SERVER */ Osal_MemCpy(bdaddr, SERVER_BDADDR, sizeof(SERVER_BDADDR)); ret = aci_hal_write_config_data(CONFIG_DATA_PUBADDR_OFFSET, CONFIG_DATA_PUBADDR_LEN, bdaddr); if(ret){ PRINTF("Setting BD_ADDR failed.\n"); } ret = aci_gatt_init(); if(ret){ PRINTF("GATT_Init failed.\n"); } if (bnrg_expansion_board == IDB05A1) { ret = aci_gap_init_IDB05A1(GAP_PERIPHERAL_ROLE_IDB05A1, 0, 0x07, &service_handle, &dev_name_char_handle, &appearance_char_handle); } else { ret = aci_gap_init_IDB04A1(GAP_PERIPHERAL_ROLE_IDB04A1, &service_handle, &dev_name_char_handle, &appearance_char_handle); } if(ret != BLE_STATUS_SUCCESS){ PRINTF("GAP_Init failed.\n"); } ret = aci_gatt_update_char_value(service_handle, dev_name_char_handle, 0, strlen(name), (uint8_t *)name); if(ret){ PRINTF("aci_gatt_update_char_value failed.\n"); while(1); } ret = aci_gap_set_auth_requirement(MITM_PROTECTION_REQUIRED, OOB_AUTH_DATA_ABSENT, NULL, 7, 16, USE_FIXED_PIN_FOR_PAIRING, 123456, BONDING); if (ret == BLE_STATUS_SUCCESS) { PRINTF("BLE Stack Initialized.\n"); } PRINTF("SERVER: BLE Stack Initialized\n"); ret = Add_Acc_Service(); if(ret == BLE_STATUS_SUCCESS) PRINTF("Acc service added successfully.\n"); else PRINTF("Error while adding Acc service.\n"); ret = Add_Environmental_Sensor_Service(); if(ret == BLE_STATUS_SUCCESS) PRINTF("Environmental Sensor service added successfully.\n"); else PRINTF("Error while adding Environmental Sensor service.\n"); #if NEW_SERVICES /* Instantiate Timer Service with two characteristics: * - seconds characteristic (Readable only) * - minutes characteristics (Readable and Notifiable ) */ ret = Add_Time_Service(); if(ret == BLE_STATUS_SUCCESS) PRINTF("Time service added successfully.\n"); else PRINTF("Error while adding Time service.\n"); /* Instantiate LED Button Service with one characteristic: * - LED characteristic (Readable and Writable) */ ret = Add_LED_Service(); if(ret == BLE_STATUS_SUCCESS) PRINTF("LED service added successfully.\n"); else PRINTF("Error while adding LED service.\n"); #endif /* Set output power level */ ret = aci_hal_set_tx_power_level(1,4); while(1) { HCI_Process(); User_Process(&axes_data); #if NEW_SERVICES Update_Time_Characteristics(); #endif } }
/* board initializition */ void ble_init_board(void) { #ifdef BLUENRG_MS uint8_t SERVER_BDADDR[] = {0x12, 0x34, 0x00, 0xE1, 0x80, 0x02}; #else uint8_t SERVER_BDADDR[] = {0x12, 0x34, 0x00, 0xE1, 0x80, 0x03}; #endif uint8_t bdaddr[BDADDR_SIZE]; int ret; /* Initialize the BlueNRG SPI driver */ BNRG_SPI_Init(); /* Initialize the BlueNRG HCI */ HCI_Init(); /* Reset BlueNRG hardware */ BlueNRG_RST(); /* The Nucleo board must be configured as SERVER */ Osal_MemCpy(bdaddr, SERVER_BDADDR, sizeof(SERVER_BDADDR)); ret = aci_hal_write_config_data(CONFIG_DATA_PUBADDR_OFFSET, CONFIG_DATA_PUBADDR_LEN, bdaddr); if(ret){ PRINTF("Setting BD_ADDR failed.\n"); } ret = aci_gatt_init(); if(ret){ PRINTF("GATT_Init failed.\n"); } #ifdef BLUENRG_MS ret = aci_gap_init(GAP_PERIPHERAL_ROLE, 0, 0x07, &service_handle, &dev_name_char_handle, &appearance_char_handle); #else ret = aci_gap_init(GAP_PERIPHERAL_ROLE, &service_handle, &dev_name_char_handle, &appearance_char_handle); #endif if(ret != BLE_STATUS_SUCCESS){ PRINTF("GAP_Init failed.\n"); } ret = aci_gap_set_auth_requirement(MITM_PROTECTION_REQUIRED, OOB_AUTH_DATA_ABSENT, NULL, 7, 16, USE_FIXED_PIN_FOR_PAIRING, 123456, BONDING); if (ret == BLE_STATUS_SUCCESS) { PRINTF("BLE Stack Initialized.\n"); } /* Set output power level */ ret = aci_hal_set_tx_power_level(1,4); /* add JUMA SERVICE*/ ret = Add_Juma_Service(); if(ret == BLE_STATUS_SUCCESS) PRINTF("JUMA service added successfully.\n"); else PRINTF("Error while adding JUMA service.\n"); }
static void BlueNRG_Init() { int rc; uint8_t bdaddr[] = {0x12, 0x34, 0x00, 0xE1, 0x80, 0x02}; uint16_t service_handle, dev_name_char_handle, appearance_char_handle; const char *ble_name = "BlueNRG"; BSP_LED_On(LED3); HCI_Init(); /* Enable and set EXTI for BlueNRG IRQ */ HAL_NVIC_SetPriority(BLUENRG_IRQ_EXTI_IRQn, 2, 0); HAL_NVIC_EnableIRQ(BLUENRG_IRQ_EXTI_IRQn); BlueNRG_RST(); BSP_LED_On(LED4); rc = aci_hal_write_config_data(CONFIG_DATA_PUBADDR_OFFSET, CONFIG_DATA_PUBADDR_LEN, bdaddr); while (rc) { HAL_Delay(100); BSP_LED_Toggle(LED4); } BSP_LED_On(LED5); rc = aci_gatt_init(); while (rc) { HAL_Delay(100); BSP_LED_Toggle(LED5); } BSP_LED_On(LED6); rc = aci_gap_init(1, &service_handle, &dev_name_char_handle, &appearance_char_handle); while (rc) { HAL_Delay(100); BSP_LED_Toggle(LED6); } BSP_LED_Off(LED3); rc = aci_gatt_update_char_value(service_handle, dev_name_char_handle, 0, strlen(ble_name), (uint8_t *)ble_name); while (rc) { HAL_Delay(100); BSP_LED_Toggle(LED3); } BSP_LED_Off(LED4); rc = aci_gap_set_auth_requirement(MITM_PROTECTION_REQUIRED, OOB_AUTH_DATA_ABSENT, NULL, 7, 16, USE_FIXED_PIN_FOR_PAIRING, 123456, BONDING); while (rc) { HAL_Delay(100); BSP_LED_Toggle(LED4); } /* sensors have been initialized in HW_Init() */ BSP_LED_Off(LED5); rc = Add_Acc_Service(); while (rc) { HAL_Delay(100); BSP_LED_Toggle(LED5); } BSP_LED_Off(LED6); rc = Add_Environmental_Sensor_Service(); while (rc) { HAL_Delay(100); BSP_LED_Toggle(LED6); } /* Init_User_Timer(); Start_User_Timer(); */ BSP_LED_On(LED3); /* -2 dBm output power */ rc = aci_hal_set_tx_power_level(1, 4); while (rc) { HAL_Delay(100); BSP_LED_Toggle(LED3); } }
/** * @brief Initialization common to all profiles * @param None * @retval None */ void BNRG_Profiles_Init(void) { int indx; uint8_t hwVersion; uint16_t fwVersion; uint8_t addr[BDADDR_SIZE] = {NULL}; HCI_Init(); /* Reset BlueNRG hardware */ BlueNRG_RST(); profileApplContext.profileGetAddressFunc(addr); /* get the BlueNRG HW and FW versions */ getBlueNRGVersion(&hwVersion, &fwVersion); /* * Reset BlueNRG again otherwise we won't * be able to change its MAC address. * aci_hal_write_config_data() must be the first * command after reset otherwise it will fail. */ BlueNRG_RST(); PRINTF("HWver %d, FWver %d", hwVersion, fwVersion); if (hwVersion > 0x30) { /* X-NUCLEO-IDB05A1 expansion board is used */ /* * Change the MAC address to avoid issues with Android cache: * if different boards have the same MAC address, Android * applications do not properly work unless you restart Bluetooth * on tablet/phone */ addr[5] = 0x03; } if(addr != NULL) { aci_hal_write_config_data(CONFIG_DATA_PUBADDR_OFFSET, CONFIG_DATA_PUBADDR_LEN, addr); } /** * Set TX Power to -2dBm. * This avoids undesired disconnection due to instability on 32KHz * internal oscillator for high transmission power. */ aci_hal_set_tx_power_level(1,4); /* #if (BLE_CURRENT_PROFILE_ROLES & HID_DEVICE) aci_gap_clear_security_database(); #endif */ PRINTF ("Profile Application: Starting BLE Profile\n"); /* initialize the security parameters */ Osal_MemSet((void *)&Security_Param, 0, sizeof(Security_Param)); Security_Param.ioCapability = SPI_HOST_MAIN_IO_CAPABILITY_NO_INPUT_NO_OUTPUT;//SPI_HOST_MAIN_IO_CAPABILITY_DISPLAY_ONLY; Security_Param.mitm_mode = SPI_HOST_MITM_PROTECTION_NOT_REQUIRED;//SPI_HOST_MITM_PROTECTION_REQUIRED; Security_Param.bonding_mode = SPI_HOST_BONDING; Security_Param.OOB_Data_Present = SPI_HOST_OOB_AUTH_DATA_ABSENT; Security_Param.Use_Fixed_Pin = SPI_HOST_USE_FIXED_PIN_FOR_PAIRING; Security_Param.encryptionKeySizeMin = 8; Security_Param.encryptionKeySizeMax = 16; Security_Param.Fixed_Pin = 111111; Security_Param.initiateSecurity = NO_SECURITY_REQUIRED; for (indx=0;indx<16;indx++){ Security_Param.OOB_Data[indx] = (uint8_t)indx; } /* initialize profile */ BLE_Profile_Init(&Security_Param, BLE_Profiles_Evt_Notify_Cb); PRINTF ("Profile Application: BLE main profile initialized. \n" ); }
int main(void) { //int ret; NVIC_SetVectorTable(NVIC_VectTab_FLASH,VECTOR_TABLE_BASE_ADDRESS); /* Identify the BlueNRG platform */ SdkEvalIdentification(); RCC_Configuration(); /* Basic button init function for handling application jumping */ Configure_Button(); #if 0 /* TBR */ PWR_PVDCmd(DISABLE); /* Disable FLASH during Sleep */ FLASH_SLEEPPowerDownCmd(ENABLE); /* Enable Ultra low power mode */ PWR_UltraLowPowerCmd(ENABLE); PWR_FastWakeUpCmd(DISABLE); #endif NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); Clock_Init(); HCI_Init(); /* Init SPI interface */ SdkEvalSpiInit(SPI_MODE_EXTI); /* Reset BlueNRG SPI interface */ BlueNRG_RST(); /* Init leds */ SdkEvalLedInit(LED1); SdkEvalLedInit(LED2); { tHalUint8 bdaddr[] = {0x12, 0x34, 0x00, 0xE1, 0x80, 0x02}; aci_hal_write_config_data(CONFIG_DATA_PUBADDR_OFFSET, CONFIG_DATA_PUBADDR_LEN, bdaddr); } aci_gatt_init(); { uint16_t service_handle, dev_name_char_handle, appearance_char_handle; aci_gap_init(1, &service_handle, &dev_name_char_handle, &appearance_char_handle); } #if 0/* TBR */ aci_gap_set_auth_requirement(MITM_PROTECTION_REQUIRED, OOB_AUTH_DATA_ABSENT, NULL, 7, 16, USE_FIXED_PIN_FOR_PAIRING, 123456, BONDING); #endif //PRINTF("BLE Stack Initialized.\n"); #ifdef ST_OTA_BTL /* Add OTA bootloader service */ Add_Btl_Service(); #endif /* -2 dBm output power */ aci_hal_set_tx_power_level(1,4); while(1) { #ifdef ST_OTA_BTL static tClockTime startTime = 0; if (Clock_Time() - startTime >led_blinking_rate) { /* LED D1 is toggling on OTA_Service Manager */ SdkEvalLedToggle(LED1); startTime = Clock_Time(); } #endif /* end ST_OTA_BTL */ HCI_Process(); if(set_connectable){ setConnectable(); set_connectable = 0; } /* Use button to switch to the basic Reset Manager */ if (GPIO_ReadInputDataBit(ButtonPort,ButtonPin) == RESET) { /* Add delay to avoid conlict with DFU activation */ Clock_Wait(2000); /* Check if an application has been loaded previously through OTA service manager */ if (*((uint32_t*) NEW_APP_MEM_INFO)!= 0) /* Service Manager will jump to the Application previously loaded at address APPLICATION_JUMP_ADDRESS */ Switch_To_OTA_Service_Manager_Application(APPLICATION_JUMP_ADDRESS); } } }