- int main(void)
- {
- /* USER CODE BEGIN 1 */
- /* USER CODE END 1 */
- /* MCU Configuration--------------------------------------------------------*/
- /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
- HAL_Init();
- /* USER CODE BEGIN Init */
- /* USER CODE END Init */
- /* Configure the system clock */
- SystemClock_Config();
- /* Configure the peripherals common clocks */
- PeriphCommonClock_Config();
- /* USER CODE BEGIN SysInit */
- /* USER CODE END SysInit */
- /* Initialize all configured peripherals */
- MX_GPIO_Init();
- MX_RADIO_Init();
- MX_RADIO_TIMER_Init();
- MX_PKA_Init();
- /* USER CODE BEGIN 2 */
- /* USER CODE END 2 */
- /* Init code for STM32_BLE */
- MX_APPE_Init(NULL);
- /* Infinite loop */
- /* USER CODE BEGIN WHILE */
- while (1)
- {
- /* USER CODE END WHILE */
- MX_APPE_Process();
- /* USER CODE BEGIN 3 */
- }
- /* USER CODE END 3 */
- }
其中初始化蓝牙的代码为
- /* Init code for STM32_BLE */
- MX_APPE_Init(NULL);
由于用了ST的蓝牙栈,所以所有的功能都是在任务中进行的,而while(1)中只有一行代码,为MX_APPE_Process();。
首先看初始化的代码,在app_entry.c中被定义,初始化代码为
- uint32_t MX_APPE_Init(void *p_param)
- {
- UNUSED(p_param);
- APP_DEBUG_SIGNAL_SET(APP_APPE_INIT);
- #if (CFG_DEBUG_APP_ADV_TRACE != 0)
- UTIL_ADV_TRACE_Init();
- UTIL_ADV_TRACE_SetVerboseLevel(VLEVEL_L); /* functional traces*/
- UTIL_ADV_TRACE_SetRegion(~0x0);
- #endif
- /* USER CODE BEGIN APPE_Init_1 */
- #if (CFG_LED_SUPPORTED == 1)
- Led_Init();
- #endif
- #if (CFG_BUTTON_SUPPORTED == 1)
- Button_Init();
- #endif
-
- #if (CFG_DEBUG_APP_TRACE != 0) && (CFG_DEBUG_APP_ADV_TRACE == 0)
- COM_InitTypeDef COM_Init =
- {
- .BaudRate = 115200,
- .WordLength= COM_WORDLENGTH_8B,
- .StopBits = COM_STOPBITS_1,
- .Parity = COM_PARITY_NONE,
- .HwFlowCtl = COM_HWCONTROL_NONE
- };
- BSP_COM_Init(COM1, &COM_Init);
-
- #endif
-
- RxUART_Init();
-
- /* USER CODE END APPE_Init_1 */
- if (HW_RNG_Init() != HW_RNG_SUCCESS)
- {
- Error_Handler();
- }
- /* Init the AES block */
- HW_AES_Init();
- HW_PKA_Init();
- APP_BLE_Init();
- #if (CFG_LPM_SUPPORTED == 1)
- /* Low Power Manager Init */
- UTIL_LPM_Init();
- #endif /* CFG_LPM_SUPPORTED */
- /* USER CODE BEGIN APPE_Init_2 */
- /* USER CODE END APPE_Init_2 */
- APP_DEBUG_SIGNAL_RESET(APP_APPE_INIT);
- return BLE_STATUS_SUCCESS;
- }
其中也初始化了串口,在下面就有串口调试相关的程序。但是进行测试后没有任何的反应,而且也不能进行仿真,不过这些不影响蓝牙功能的使用。
在网页版调试蓝牙的时候同时打开串口会发现在收到蓝牙指令后会打印如下内容
- -- GATT : LED CONFIGURATION RECEIVED
- -- P2P APPLICATION SERVER : LED1 ON
看其意思应该是板卡收到打开LED1的指令,所以可以全局搜索以上内容可以找到蓝牙接收入口。不过也可以搜索APP_DBG_MSG函数,该函数的功能是向串口打印调试信息。蓝牙接收到数据的函数名为P2P_SERVER_Notification,在文件p2p_server_app.c中。
可以在该文件的前面看到相关协议的定义,定义如下
- #define P2P_SERVER_UUID 0x8f,0xe5,0xb3,0xd5,0x2e,0x7f,0x4a,0x98,0x2a,0x48,0x7a,0xcc,0x40,0xfe,0x00,0x00
- #define LED_C_UUID 0x19,0xed,0x82,0xae,0xed,0x21,0x4c,0x9d,0x41,0x45,0x22,0x8e,0x41,0xfe,0x00,0x00
- #define SWITCH_C_UUID 0x19,0xed,0x82,0xae,0xed,0x21,0x4c,0x9d,0x41,0x45,0x22,0x8e,0x42,0xfe,0x00,0x00