记录一下 BlueNRG移植HID例程到STSW-STLKT01 v1.2.0的过程
[复制链接]
打开STSW-STLKT01 v1.2.0\Projects\SensorTile\Applications\BLE_SampleApp\EWARM和 \OSXSmartConnPS_V1.6.0\Projects\Multi\Applications\Profiles_LowPower\EWARM\STM32L476RG-Nucleo 复制OSXSmartConnPS_V1.6.0\Middlewares\ST\STM32_BlueNRG下的所有文件到 STSW-STLKT01 v1.2.0\Middlewares\ST\STM32_BlueNRG 替换文件夹不替换文件(复制STSW-STLKT01 v1.2.0中没有的文件,但不覆盖已有的文件) 分别打开2个项目的”Options”选项卡,找到”C/C++ Compiler”下的”Preprocessor” 点Additional include directories右边的按钮
对比2个项目的引用文件夹 把OSXSmartConnPS_V1.6.0\Projects\Multi\Applications\Profiles_LowPower\EWARM\STM32L476RG-Nucleo 项目里多出的文件夹复制到 STSW-STLKT01 v1.2.0\Projects\SensorTile\Applications\BLE_SampleApp\EWARM 项目中
复制STM32CubeExpansion_BLE1_V2.8.0\Middlewares\ST下的所有文件夹到 STSW-STLKT01 v1.2.0\Middlewares\ST\ 文件夹替换,文件不替换
复制OSXSmartConnPS_V1.6.0\Projects\Multi\Applications\Profiles_LowPower文件夹下的 STM32xx_HAL_APP_Drivers到 STSW-STLKT01 v1.2.0\Projects\SensorTile\Applications\BLE_SampleApp 两个项目的文件夹深度不一样,需要把新复制来的文件夹中多出的”..\”去掉 并添加$PROJ_DIR$\..\STM32xx_HAL_APP_Drivers\inc到BLE_SampleApp项目里
这时编译BLE_SampleApp项目应该不会有错误,确保移植时没有修改已有的文件 复制OSXSmartConnPS_V1.6.0\Projects\Multi\Applications\Profiles_LowPower\Inc 下的所有文件到 STSW-STLKT01 v1.2.0\Projects\SensorTile\Applications\BLE_SampleApp\Inc 选择不覆盖 添加头文件到BLE_SampleApp 项目的main.c #include "low_power_conf.h" #include "profile_application.h" #include "stm32xx_timerserver.h" #include "stm32xx_hal_app_rtc.h" 修改low_power_conf.h文件,注释掉#include "stm32l4xx_nucleo.h" #ifdef USE_STM32L4XX_NUCLEO #include "stm32l4xx_hal.h" //#include "stm32l4xx_nucleo.h" #include "stm32l4xx_hal_rtc.h" #include "stm32l4xx_hal_rtc_ex.h" 添加下边代码到main.c文件中 tProfileApplContext profileApplContext; /* Profile Application Context */ RTC_HandleTypeDef hrtc; /* RTC handler declaration */ extern volatile uint8_t send_measurement; #if (BLE_CURRENT_PROFILE_ROLES & HID_DEVICE) extern volatile uint8_t skip_hid_tick_inc; extern volatile uint8_t hid_tick; #endif static void Init_RTC(void); 复制下边2个函数到main.c /** * @brief Initialize RTC block * * @note * @param None * @retval None */ static void Init_RTC(void) { /* Initialize the HW - 37Khz LSI being used */ /* Enable the LSI clock */ __HAL_RCC_LSI_ENABLE(); /* Enable power module clock */ __PWR_CLK_ENABLE(); /* Enable acces to the RTC registers */ HAL_PWR_EnableBkUpAccess(); /** * Write twice the value to flush the APB-AHB bridge * This bit shall be written in the register before writing the next one */ HAL_PWR_EnableBkUpAccess(); /* Select LSI as RTC Input */ __HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSI); /* Enable RTC */ __HAL_RCC_RTC_ENABLE(); hrtc.Instance = RTC; /**< Define instance */ hrtc.Lock = HAL_UNLOCKED; /**< Initialize lock */ hrtc.State = HAL_RTC_STATE_READY; /**< Initialize state */ /** * Bypass the shadow register */ HAL_RTCEx_EnableBypassShadow(&hrtc); /** * Set the Asynchronous prescaler */ hrtc.Init.AsynchPrediv = RTC_ASYNCH_PRESCALER; hrtc.Init.SynchPrediv = RTC_SYNCH_PRESCALER; HAL_RTC_Init(&hrtc); /* Disable Write Protection */ __HAL_RTC_WRITEPROTECTION_DISABLE(&hrtc); HAL_APP_RTC_Set_Wucksel(&hrtc, WUCKSEL_DIVIDER); /**< Tick timer is 55us */ /* Wait for LSI to be stable */ while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSIRDY) == 0); return; } void TIMER_Notification(eTimerProcessID_t eTimerProcessID, uint8_t ubTimerID, pf_TIMER_TimerCallBack_t pfTimerCallBack) { uint32_t uwPRIMASK_Bit = __get_PRIMASK(); /**< backup PRIMASK bit */; switch (eTimerProcessID) { case eTimerModuleID_BlueNRG_Profile_App: #if !((BLE_CURRENT_PROFILE_ROLES & ALERT_NOTIFICATION_SERVER) || (BLE_CURRENT_PROFILE_ROLES & HID_DEVICE)) /* Clear Wake Up Flag */ __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ send_measurement++; __set_PRIMASK(uwPRIMASK_Bit); /**< Restore PRIMASK bit*/ #endif #if (BLE_CURRENT_PROFILE_ROLES & HID_DEVICE) if(skip_hid_tick_inc == 0) { /* Clear Wake Up Flag */ __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ hid_tick++; __set_PRIMASK(uwPRIMASK_Bit); /**< Restore PRIMASK bit*/ } #endif break; default: if (pfTimerCallBack != 0) { pfTimerCallBack(); } break; } } 复制下边代码到main.c /* Configure the system in Low Power Mode */ if (low_power_enabled) { SystemPower_Config(); } /* Initialize the Profile Application Context's Data Structures */ Osal_MemSet(&profileApplContext,0,sizeof(tProfileApplContext)); /* Configure the RTC */ Init_RTC(); TIMER_Init(&hrtc); TIMER_Create(eTimerModuleID_BlueNRG_Profile_App, &(profileApplContext.profileTimer_Id), eTimerMode_Repeated, 0); /* Initialize the BlueNRG SPI driver */ BNRG_SPI_Init(); /* Set current BlueNRG profile (HRM, HTM, GS, ...) */ BNRG_Set_Current_profile(); /* Initialize the BlueNRG Profile */ /* set tx power and security parameters (common to all profiles) */ BNRG_Profiles_Init(); /* low level profile initialization (profile specific) */ profileApplContext.initProfileFunc(); BLE_Profile_Write_DeviceState(APPL_UNINITIALIZED); 复制下边代码到main.c /* Exported defines -----------------------------------------------------------*/ #define HCLK_32MHZ 0 /* can be set to 1 only for STM32L053xx */ #define HCLK_80MHZ 0 /* can be set to 1 only for STM32L476RG */ /* SO: TO BE VERIFIED FOR L4. Do not use by now. */ #define HCLK_84MHZ 0 /* can be set to 1 only for STM32F401xE */ /** * RTC cloc divider */ #define WUCKSEL_DIVIDER (3) /**< Tick is (LSI speed clock/2) */ #define RTC_ASYNCH_PRESCALER (1) #define RTC_SYNCH_PRESCALER (0xFFFF) 删除main.c中的下边代码 /* Initialize the BlueNRG */ Init_BlueNRG_Stack(); /* Initialize the BlueNRG Custom services */ Init_BlueNRG_Custom_Services(); 删除main.c中的下边2个函数 /** @brief Initialize the BlueNRG Stack * @param None * @retval None */ static void Init_BlueNRG_Stack(void) { const char BoardName[8] = {NAME_STLBLE,0}; uint16_t service_handle, dev_name_char_handle, appearance_char_handle; int ret; uint8_t hwVersion; uint16_t fwVersion; #ifdef STATIC_BLE_MAC { uint8_t tmp_bdaddr[6]= {STATIC_BLE_MAC}; int32_t i; for(i=0;i<6;i++) bdaddr = tmp_bdaddr; } #endif /* STATIC_BLE_MAC */ /* 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); if (hwVersion > 0x30) { /* X-NUCLEO-IDB05A1 expansion board is used */ TargetBoardFeatures.bnrg_expansion_board = IDB05A1; } else { /* X-NUCLEO-IDB0041 expansion board is used */ TargetBoardFeatures.bnrg_expansion_board = IDB04A1; } /* * Reset BlueNRG again otherwise it will fail. */ BlueNRG_RST(); #ifndef STATIC_BLE_MAC /* Create a Unique BLE MAC */ { bdaddr[0] = (STM32_UUID[1]>>24)&0xFF; bdaddr[1] = (STM32_UUID[0] )&0xFF; bdaddr[2] = (STM32_UUID[2] >>8)&0xFF; bdaddr[3] = (STM32_UUID[0]>>16)&0xFF; bdaddr[4] = (((STLBLE_VERSION_MAJOR-48)*10) + (STLBLE_VERSION_MINOR-48)+100)&0xFF; bdaddr[5] = 0xC0; /* for a Legal BLE Random MAC */ } #else /* STATIC_BLE_MAC */ ret = aci_hal_write_config_data(CONFIG_DATA_PUBADDR_OFFSET, CONFIG_DATA_PUBADDR_LEN, bdaddr); if(ret){ STLBLE_PRINTF("\r\nSetting Pubblic BD_ADDR failed\r\n"); goto fail; } #endif /* STATIC_BLE_MAC */ ret = aci_gatt_init(); if(ret){ STLBLE_PRINTF("\r\nGATT_Init failed\r\n"); goto fail; } if (TargetBoardFeatures.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){ STLBLE_PRINTF("\r\nGAP_Init failed\r\n"); goto fail; } #ifndef STATIC_BLE_MAC ret = hci_le_set_random_address(bdaddr); if(ret){ STLBLE_PRINTF("\r\nSetting the Static Random BD_ADDR failed\r\n"); goto fail; } #endif /* STATIC_BLE_MAC */ ret = aci_gatt_update_char_value(service_handle, dev_name_char_handle, 0, 7/*strlen(BoardName)*/, (uint8_t *)BoardName); if(ret){ STLBLE_PRINTF("\r\naci_gatt_update_char_value failed\r\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) { STLBLE_PRINTF("\r\nGAP setting Authentication failed\r\n"); goto fail; } STLBLE_PRINTF("SERVER: BLE Stack Initialized \r\n" "\t\tBoard type=%s HWver=%d, FWver=%d.%d.%c\r\n" "\t\tBoardName= %s\r\n" "\t\tBoardMAC = %x:%x:%x:%x:%x:%x\r\n\n", "SensorTile", hwVersion, fwVersion>>8, (fwVersion>>4)&0xF, (hwVersion > 0x30) ? ('a'+(fwVersion&0xF)-1) : 'a', BoardName, bdaddr[5],bdaddr[4],bdaddr[3],bdaddr[2],bdaddr[1],bdaddr[0]); /* Set output power level */ aci_hal_set_tx_power_level(1,4); return; fail: return; } /** @brief Initialize all the Custom BlueNRG services * @param None * @retval None */ static void Init_BlueNRG_Custom_Services(void) { int ret; ret = Add_HWServW2ST_Service(); if(ret == BLE_STATUS_SUCCESS) { STLBLE_PRINTF("HW Service W2ST added successfully\r\n"); } else { STLBLE_PRINTF("\r\nError while adding HW Service W2ST\r\n"); } ret = Add_ConfigW2ST_Service(); if(ret == BLE_STATUS_SUCCESS) { STLBLE_PRINTF("Config Service W2ST added successfully\r\n"); } else { STLBLE_PRINTF("\r\nError while adding Config Service W2ST\r\n"); } } 添加左边2个文件夹和文件到BLE_SampleApp的Middlewares中
去掉stm32l4xx_hal_conf.h 文件中#define HAL_RTC_MODULE_ENABLED的注释 添加stm32l4xx_hal_rtc.c、stm32l4xx_hal_pwr_ex.c到项目的 Drivers\STM32L4xx_HAL_Driver文件夹 复制STM32CubeExpansion_BLE1_V2.8.0\Projects\Multi\Applications\Profiles_LowPower\Src 文件夹下的hid_profile_application.c、profile_application.c、cube_hal_l4.c、low_power_conf_l4.c 到STSW-STLKT01 v1.2.0\Projects\SensorTile\Applications\BLE_SampleApp\Src 并添加到项目中 修改个文件中的#include "bluenrg_interface.h"为#include "SensorTile_BlueNRG.h" 注释掉hid_profile_application.c中的BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI); 在项目的Drivers\Middlewares下新建BlueProfileLib文件夹,添加 Middlewares\ST\STM32_BlueNRG\Prof_Periph_Lib\EWARM\L4\BLEProfilesLib.a文件 User下的sensor_service.c 删除main.c下的下边代码 /** * @brief Send Environmetal Data (Temperature/Pressure/Humidity) to BLE * @param None * @retval None */ static void SendEnvironmentalData(void) { uint8_t Status; #ifdef ENABLE_USB_DEBUG_NOTIFY_TRAMISSION if(W2ST_CHECK_CONNECTION(W2ST_CONNECT_STD_TERM)) { BytesToWrite = sprintf((char *)BufferToWrite,"Sending: "); Term_Update(BufferToWrite,BytesToWrite); } else { STLBLE_PRINTF("Sending: "); } #endif /* ENABLE_USB_DEBUG_NOTIFY_TRAMISSION */ /* Pressure,Humidity, and Temperatures*/ if(W2ST_CHECK_CONNECTION(W2ST_CONNECT_ENV)) { float SensorValue; int32_t PressToSend=0; uint16_t HumToSend=0; int16_t Temp2ToSend=0,Temp1ToSend=0; int32_t decPart, intPart; if(TargetBoardFeatures.HandlePressSensor) { if(BSP_PRESSURE_IsInitialized(TargetBoardFeatures.HandlePressSensor,&Status)==COMPONENT_OK) { BSP_PRESSURE_Get_Press(TargetBoardFeatures.HandlePressSensor,(float *)&SensorValue); MCR_BLUEMS_F2I_2D(SensorValue, intPart, decPart); PressToSend=intPart*100+decPart; #ifdef ENABLE_USB_DEBUG_NOTIFY_TRAMISSION if(W2ST_CHECK_CONNECTION(W2ST_CONNECT_STD_TERM)) { BytesToWrite = sprintf((char *)BufferToWrite,"Press=%ld ",PressToSend); Term_Update(BufferToWrite,BytesToWrite); } else { STLBLE_PRINTF("Press=%ld ",PressToSend); } #endif /* ENABLE_USB_DEBUG_NOTIFY_TRAMISSION */ } } if(TargetBoardFeatures.HandleHumSensor) { if(BSP_HUMIDITY_IsInitialized(TargetBoardFeatures.HandleHumSensor,&Status)==COMPONENT_OK){ BSP_HUMIDITY_Get_Hum(TargetBoardFeatures.HandleHumSensor,(float *)&SensorValue); MCR_BLUEMS_F2I_1D(SensorValue, intPart, decPart); HumToSend = intPart*10+decPart; #ifdef ENABLE_USB_DEBUG_NOTIFY_TRAMISSION if(W2ST_CHECK_CONNECTION(W2ST_CONNECT_STD_TERM)) { BytesToWrite = sprintf((char *)BufferToWrite,"Hum=%d ",HumToSend); Term_Update(BufferToWrite,BytesToWrite); } else { STLBLE_PRINTF("Hum=%d ",HumToSend); } #endif /* ENABLE_USB_DEBUG_NOTIFY_TRAMISSION */ } } if(TargetBoardFeatures.NumTempSensors==2) { if(BSP_TEMPERATURE_IsInitialized(TargetBoardFeatures.HandleTempSensors[0],&Status)==COMPONENT_OK){ BSP_TEMPERATURE_Get_Temp(TargetBoardFeatures.HandleTempSensors[0],(float *)&SensorValue); MCR_BLUEMS_F2I_1D(SensorValue, intPart, decPart); Temp1ToSend = intPart*10+decPart; #ifdef ENABLE_USB_DEBUG_NOTIFY_TRAMISSION if(W2ST_CHECK_CONNECTION(W2ST_CONNECT_STD_TERM)) { BytesToWrite = sprintf((char *)BufferToWrite,"Temp=%d ",Temp1ToSend); Term_Update(BufferToWrite,BytesToWrite); } else { STLBLE_PRINTF("Temp=%d ",Temp1ToSend); } #endif /* ENABLE_USB_DEBUG_NOTIFY_TRAMISSION */ } if(BSP_TEMPERATURE_IsInitialized(TargetBoardFeatures.HandleTempSensors[1],&Status)==COMPONENT_OK){ BSP_TEMPERATURE_Get_Temp(TargetBoardFeatures.HandleTempSensors[1],(float *)&SensorValue); MCR_BLUEMS_F2I_1D(SensorValue, intPart, decPart); Temp2ToSend = intPart*10+decPart; #ifdef ENABLE_USB_DEBUG_NOTIFY_TRAMISSION if(W2ST_CHECK_CONNECTION(W2ST_CONNECT_STD_TERM)) { BytesToWrite = sprintf((char *)BufferToWrite,"Temp2=%d ",Temp2ToSend); Term_Update(BufferToWrite,BytesToWrite); } else { STLBLE_PRINTF("Temp2=%d ",Temp2ToSend); } #endif /* ENABLE_USB_DEBUG_NOTIFY_TRAMISSION */ } } else if(TargetBoardFeatures.NumTempSensors==1) { if(BSP_TEMPERATURE_IsInitialized(TargetBoardFeatures.HandleTempSensors[0],&Status)==COMPONENT_OK){ BSP_TEMPERATURE_Get_Temp(TargetBoardFeatures.HandleTempSensors[0],(float *)&SensorValue); MCR_BLUEMS_F2I_1D(SensorValue, intPart, decPart); Temp1ToSend = intPart*10+decPart; #ifdef ENABLE_USB_DEBUG_NOTIFY_TRAMISSION if(W2ST_CHECK_CONNECTION(W2ST_CONNECT_STD_TERM)) { BytesToWrite = sprintf((char *)BufferToWrite,"Temp1=%d ",Temp1ToSend); Term_Update(BufferToWrite,BytesToWrite); } else { STLBLE_PRINTF("Temp1=%d ",Temp1ToSend); } #endif /* ENABLE_USB_DEBUG_NOTIFY_TRAMISSION */ } } Environmental_Update(PressToSend,HumToSend,Temp2ToSend,Temp1ToSend); } #ifdef ENABLE_USB_DEBUG_NOTIFY_TRAMISSION if(W2ST_CHECK_CONNECTION(W2ST_CONNECT_STD_TERM)) { BytesToWrite = sprintf((char *)BufferToWrite,"\r\n"); Term_Update(BufferToWrite,BytesToWrite); } else { STLBLE_PRINTF("\r\n"); } #endif /* ENABLE_USB_DEBUG_NOTIFY_TRAMISSION */ } 删除main.c下的 static void SendEnvironmentalData(void); static void Init_BlueNRG_Custom_Services(void); static void Init_BlueNRG_Stack(void); 删除main.c下的 #include "bluenrg_utils.h" 项目项目下的Middlewares\STM32_BlueNRG\HCI\Controller\bluenrg_utils.c 替换\OSXSmartConnPS_V1.6.0\Projects\Multi\Applications\Profiles_LowPower\EWARM\STM32L476RG-Nucleo\项目main.c里main函数中的while()内容到 STSW-STLKT01 v1.2.0\Projects\SensorTile\Applications\BLE_SampleApp\EWARM项目main.c里的main函数中的while()内容 删除cube_hal.h下的 #include "stm32l4xx_nucleo.h" #include "stm32l4xx_nucleo_bluenrg.h" 添加ST\STM32_BlueNRG\Prof_Periph\utils\timer.c到项目目录Middlewares\STM32_BlueNRG\HCI\Utils中 添加下边代码到main.c volatile uint8_t send_measurement = 0; 项目中新建HAL_APP_Drivers文件夹添加 STSW-STLKT01 v1.2.0\Projects\SensorTile\Applications\BLE_SampleApp\STM32xx_HAL_APP_Drivers\src\stm32xx_hal_app_rtc.c 到文件夹中 删除main.c中的 /* initialize timers */ InitTimers(); StartTime = HAL_GetTick(); /* Start the main processes */ 删除 /** * @brief Function for initializing timers for sending the information to BLE: * - 1 for sending MotionFX/AR/CP and Acc/Gyro/Mag * - 1 for sending the Environmental info * @param None * @retval None */ static void InitTimers(void) { uint32_t uwPrescalerValue; /* Timer Output Compare Configuration Structure declaration */ TIM_OC_InitTypeDef sConfig; /* Compute the prescaler value to have TIM3 counter clock equal to 10 KHz */ uwPrescalerValue = (uint32_t) ((SystemCoreClock / 10000) - 1); /* Set TIM1 instance (Motion)*/ /* Set TIM1 instance */ TimCCHandle.Instance = TIM1; TimCCHandle.Init.Period = 65535; TimCCHandle.Init.Prescaler = uwPrescalerValue; TimCCHandle.Init.ClockDivision = 0; TimCCHandle.Init.CounterMode = TIM_COUNTERMODE_UP; if(HAL_TIM_OC_Init(&TimCCHandle) != HAL_OK) { /* Initialization Error */ Error_Handler(); } /* Configure the Output Compare channels */ /* Common configuration for all channels */ sConfig.OCMode = TIM_OCMODE_TOGGLE; sConfig.OCPolarity = TIM_OCPOLARITY_LOW; /* Output Compare Toggle Mode configuration: Channel1 */ sConfig.Pulse = uhCCR1_Val; if(HAL_TIM_OC_ConfigChannel(&TimCCHandle, &sConfig, TIM_CHANNEL_1) != HAL_OK) { /* Configuration Error */ Error_Handler(); } } /** * @brief System Clock Configuration * @param None * @retval None */ void SystemClock_Config(void) { RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0}; __HAL_RCC_PWR_CLK_ENABLE(); HAL_PWR_EnableBkUpAccess(); /* Enable the LSE Oscilator */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE; RCC_OscInitStruct.LSEState = RCC_LSE_ON; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK){ while(1); } /* Enable the CSS interrupt in case LSE signal is corrupted or not present */ HAL_RCCEx_DisableLSECSS(); /* Enable MSI Oscillator and activate PLL with MSI as source */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI; RCC_OscInitStruct.MSIState = RCC_MSI_ON; RCC_OscInitStruct.HSICalibrationValue = RCC_MSICALIBRATION_DEFAULT; RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_11; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI; RCC_OscInitStruct.PLL.PLLM = 6; RCC_OscInitStruct.PLL.PLLN = 40; RCC_OscInitStruct.PLL.PLLP = 7; RCC_OscInitStruct.PLL.PLLQ = 4; RCC_OscInitStruct.PLL.PLLR = 4; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK){ while(1); } /* Enable MSI Auto-calibration through LSE */ HAL_RCCEx_EnableMSIPLLMode(); /* Select MSI output as USB clock source */ PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USB; PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_MSI; HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */ RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK){ while(1); } } 取消SensorTile_BlueNRG.h中#define RTC_WAKEUP_IRQHandler RTC_WKUP_IRQHandler 的注释 添加下边代码到stm32l4xx_it.c void RTC_WAKEUP_IRQHandler(void) { TIMER_RTC_Wakeup_Handler(); } 有东西功能已经完成,下载例程后连接手机会出现鼠标指针
有一个说小不小的问题是在main函数的while里如果不注释掉LPM_Enter_Mode();执行后退不出低功耗
|