打印
[信息]

BlueMicrosystem2_V2.1.3标准例程测试及简单解读

[复制链接]
380|6
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
jcky001|  楼主 | 2020-12-14 09:48 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
该技术贴针对STSW-STLKT01例程里的LSM6DSM加速度传感器的初始化解读了函数的调用过程,大体的调用过程如下:
main.c ->SensorTile_accelero.c –> LSM6DSM_ACC_GYRO_driver_HL.c -> LSM6DSM_ACC_GYRO_driver.c -> SensorTile.c -> stm32l4xx_hal_gpio.c

main.c ->SensorTile_accelero.c –> LSM6DSM_ACC_GYRO_driver_HL.c -> LSM6DSM_ACC_GYRO_driver.c -> SensorTile.c ->stm32l4xx_hal_spi.h



通过这两个步骤解决了传感器的初始化过程。

翌日,我对BlueMicrosystem2_V2.1.3的main函数进行了研究,总体的流程是这样的:

1.首先是编译器的选择以及变量定义、函数声明,此处省略无数字;
进入int main(void)主函数:
  • HAL_Init();

复制代码



HAL的初始化,什么是HAL呢,其实就是硬件抽象层。
硬件抽象层是位于操作系统 内核与硬件电路之间的接口层,其目的在于将硬件抽象化。它隐藏了特定平台的硬件接口细节,为操作系统提供虚拟硬件平台,使其具有硬件无关性,可在多种平台上进行移植。 从软硬件测试的角度来看,软硬件的测试工作都可分别基于硬件抽象层来完成,使得软硬件测试工作的并行进行成为可能。


2.硬件抽象层初始化完成之后,进行
  • JumpToBootloader();

复制代码

  • RestartInBootLoaderMode = 0x0;

复制代码


启动BootLoader。BootLoader是在操作系统内核运行之前运行。可以初始化硬件设备、建立内存空间映射图,从而将系统的软硬件环境带到一个合适状态,以便为最终调用操作系统内核备好正确的环境。

3.系统的时钟配置
  • SystemClock_Config();
  • Sensor_IO_SPI_CS_Init_All();
  • InitTargetPlatform(TARGET_NUCLEO);或者InitTargetPlatform(TARGET_NUCLEO);
  • InitLicenseManager();


复制代码




4.输出一些版本信息
5.初始化蓝牙服务
  •   Init_BlueNRG_Stack();
  • Init_BlueNRG_Custom_Services();

复制代码




6.设置加速度计的级别为2G
  •   Set2GAccelerometerFullScale();

复制代码



读取加速度计的灵敏度
  •   BSP_ACCELERO_Get_Sensitivity(TargetBoardFeatures.HandleAccSensor,&sensitivity);
  •   sensitivity_Mul = sensitivity * ((float) FROM_MG_TO_G);

复制代码




7.初始化定时器
  •   InitTimers();

复制代码



8.判断校准是不是在内存中已经使用,进行控制,然后设置起始时间
  • if(LicensesIndexMap[OSX_MOTION_FX] != -1)
  •   {
  •     if(osxLicencesManager.LicVector[LicensesIndexMap[OSX_MOTION_FX]].osxLicenseInitialized) {
  •       ReCallCalibrationFromMemory(osxLicencesManager.Header.MagnetoCalibration);
  •     }
  •   }
  •   StartTime = HAL_GetTick();

复制代码




9.此时初始化完成,开始进入运行的wihle(1)循环,在其中控制指示灯的闪烁频率,并且通过中断的方式来实现各个传感器数据的读取,以完成整个系统的常规运行。

  •   while (1){
  •     /* Led Blinking when there is not a client connected */
  •     if(!connected) {
  •       if(!TargetBoardFeatures.LedStatus) {
  •         if(HAL_GetTick()-StartTime > 1000) {
  •           LedOnTargetPlatform();
  •           TargetBoardFeatures.LedStatus =1;
  •           StartTime = HAL_GetTick();
  •         }
  •       } else {
  •         if(HAL_GetTick()-StartTime > 50) {
  •           LedOffTargetPlatform();
  •           TargetBoardFeatures.LedStatus =0;
  •           StartTime = HAL_GetTick();
  •         }
  •       }
  •     }
  •     /* Handle Interrupt from MEMS */
  •     if(MEMSInterrupt) {
  •       MEMSCallback();
  •       MEMSInterrupt=0;
  •     }
  •     /* Handle user button */
  •     if(ButtonPressed) {
  •       ButtonCallback();
  •       ButtonPressed=0;      
  •     }
  •     /* Handle Re-Calibration */
  •     if(ForceReCalibration) {
  •       ForceReCalibration=0;
  •       ReCalibration();
  •     }
  •     /* handle BLE event */
  •     if(HCI_ProcessEvent) {
  •       HCI_ProcessEvent=0;
  •       HCI_Process();
  •     }
  •     if(set_connectable){
  •       /* Initializes the osx libraries if there is a valid license */
  •       /* Initialize MotionFX library */
  •       if(LicensesIndexMap[OSX_MOTION_FX] != -1){
  •         if((osxLicencesManager.LicVector[LicensesIndexMap[OSX_MOTION_FX]].osxLicenseInitialized) & (TargetBoardFeatures.osxMotionFXIsInitalized==0)){
  •           MotionFX_manager_init();
  •           MotionFX_manager_start_9X();
  •         }
  •       }
  • #ifdef OSX_BMS_MOTIONAR
  •       /* Initialize MotionAR Library */
  •       if(LicensesIndexMap[OSX_MOTION_AR] != -1){
  •         if((osxLicencesManager.LicVector[LicensesIndexMap[OSX_MOTION_AR]].osxLicenseInitialized) & (TargetBoardFeatures.osxMotionARIsInitalized==0)){
  •           MotionAR_manager_init();
  •         }
  •       }
  • #endif /* OSX_BMS_MOTIONAR */
  • #ifdef OSX_BMS_MOTIONCP
  •       /* Initialize MotionCP Library */
  •       if(LicensesIndexMap[OSX_MOTION_CP] != -1){
  •         if((osxLicencesManager.LicVector[LicensesIndexMap[OSX_MOTION_CP]].osxLicenseInitialized) & (TargetBoardFeatures.osxMotionCPIsInitalized==0)){
  •           MotionCP_manager_init();
  •         }
  •       }
  • #endif /* OSX_BMS_MOTIONCP */
  • #ifdef OSX_BMS_MOTIONGR
  •       /* Initialize MotionGR Library */
  •       if(LicensesIndexMap[OSX_MOTION_GR] != -1){
  •         if((osxLicencesManager.LicVector[LicensesIndexMap[OSX_MOTION_GR]].osxLicenseInitialized) & (TargetBoardFeatures.osxMotionGRIsInitalized==0)){
  •           MotionGR_manager_init();
  •         }
  •       }
  • #endif /* OSX_BMS_MOTIONGR */
  • #ifdef OSX_BMS_ACOUSTIC_SOURCE_LOCALIZATION
  •       /* Initialize AcousticSL Library */
  •       if(LicensesIndexMap[OSX_ACOUSTIC_SL] != -1){
  •         if((osxLicencesManager.LicVector[LicensesIndexMap[OSX_ACOUSTIC_SL]].osxLicenseInitialized) & (TargetBoardFeatures.osxAcousticSLIsInitalized==0)){
  •           AcousticSL_Manager_init();
  •         }
  •       }
  • #endif /* OSX_BMS_ACOUSTIC_SOURCE_LOCALIZATION */
  • #ifdef OSX_BMS_BLUEVOICE
  •       /* Initialize BlueVoice Library */
  •       if(LicensesIndexMap[OSX_AUDIO_BV] != -1) {
  •         if((osxLicencesManager.LicVector[LicensesIndexMap[OSX_AUDIO_BV]].osxLicenseInitialized) & (TargetBoardFeatures.osxAudioBVIsInitalized==0)){
  •           AudioBV_Manager_init();
  •         }
  •       }
  • #endif /* OSX_BMS_BLUEVOICE */
  •       if(NecessityToSaveLicense!=0) {
  •         if(NecessityToSaveLicense & OSX_BMS_RESET_LIC) {
  •           /* Reset before write data in Memory */
  •           NecessityToSaveLicense &= (~OSX_BMS_RESET_LIC);
  •           ResetLicensesStatus();
  •         }
  •         if(NecessityToSaveLicense & OSX_BMS_SAVE_LIC) {
  •           /* Save the data in Memory */
  •           NecessityToSaveLicense &= (~OSX_BMS_SAVE_LIC);
  •           SaveLicensesStatus();
  •         }
  •       }
  • #if 0
  •       /* Update the BlueNRG firmware */
  •       if(MakeUpdateBlueNRG){
  •         UpdateFWBlueNRG(SizeOfUpdateBlueNRG);
  •         MakeUpdateBlueNRG=0;
  •         /* Restart the Bluethoot services */
  •         /* Initialize the BlueNRG */
  •         Init_BlueNRG_Stack();
  •         /* Initialize the BlueNRG Custom services */
  •         Init_BlueNRG_Custom_Services();
  •       }
  • #endif
  •       /* Now update the BLE advertize data and make the Board connectable */
  •       setConnectable();
  •       set_connectable = FALSE;
  • #ifdef USE_STM32F4XX_NUCLEO
  •         //BSP_AUDIO_IN_Record(PDM_Buffer, 0);
  • #endif /* USE_STM32F4XX_NUCLEO */
  •     }
  •     /* Environmental Data */
  •     if(SendEnv) {
  •       SendEnv=0;
  •       SendEnvironmentalData();
  •     }
  •    
  •     /* Mic Data */
  •     if (SendAudioLevel) {
  •       SendAudioLevel = 0;
  •       SendAudioLevelData();
  •     }
  •     /* Motion Data */
  •     if(SendAccGyroMag) {
  •       SendAccGyroMag=0;
  •       SendMotionData();
  •     }
  •     /* osxMotionFX */
  •     if(Quaternion) {
  •       Quaternion=0;
  •       ComputeQuaternions();
  •     }
  • #ifdef OSX_BMS_BLUEVOICE
  •     /* BlueVoice Data */
  •     if(SendBlueVoice){
  •       osx_BlueVoice_SendData(&num_byte_sent);
  •       SendBlueVoice = 0;
  •     }
  • #endif /* OSX_BMS_BLUEVOICE */
  • #ifdef OSX_BMS_MOTIONAR
  •     /* osxMotionAR */
  •     if(UpdateMotionAR) {
  •       UpdateMotionAR=0;
  •       ComputeMotionAR();
  •     }
  • #endif /* OSX_BMS_MOTIONAR */
  • #ifdef OSX_BMS_MOTIONCP
  •     /* osxMotionCP */
  •     if(UpdateMotionCP) {
  •       UpdateMotionCP=0;
  •       ComputeMotionCP();
  •     }
  • #endif /* OSX_BMS_MOTIONCP */
  • #ifdef OSX_BMS_MOTIONGR
  •     /* osxMotionGR */
  •     if(UpdateMotionGR) {
  •       UpdateMotionGR=0;
  •       ComputeMotionGR();
  •     }
  • #endif /* OSX_BMS_MOTIONGR */
  •    
  • #ifdef OSX_BMS_ACOUSTIC_SOURCE_LOCALIZATION   
  •     /* Audio Source Localization Data */
  •     if (SendAudioSourceLocalization)
  •     {
  •       SendAudioSourceLocalization = 0;
  •       SendAudioSourceLocalizationData();
  •     }
  • #endif /* OSX_BMS_ACOUSTIC_SOURCE_LOCALIZATION */
  •     /* Wait for Event */
  •     __WFI();
  •   }

复制代码






使用特权

评论回复
沙发
xinxianshi| | 2020-12-14 21:55 | 只看该作者
感觉跟STM32的库函数类似。

使用特权

评论回复
板凳
coshi| | 2021-1-7 20:30 | 只看该作者
读代码有些发愁啊

使用特权

评论回复
地板
aoyi| | 2021-1-7 20:31 | 只看该作者
需要自己运行一下试试看

使用特权

评论回复
5
drer| | 2021-1-7 20:33 | 只看该作者
能贴一下判断的流程吗

使用特权

评论回复
6
kxsi| | 2021-1-7 20:37 | 只看该作者
有些跳转条件需要好好分析

使用特权

评论回复
7
nawu| | 2021-1-7 20:42 | 只看该作者
传感器读取的间隔是多少啊

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1481

主题

4247

帖子

6

粉丝