|
sersontile之Bluemicrosystem2、DataLog固件库代码分析
[复制链接]
1、Bluemicrosystem2
从main函数看起:
首先初始化HAL_Init();
然后配置时钟SystemClock_Config();
#ifdef STM32_NUCLEO
InitTargetPlatform(TARGET_NUCLEO);
#elif STM32_SENSORTILE
InitTargetPlatform(TARGET_SENSORTILE);
#endif /* STM32_NUCLEO */
因为是在sersontile上运行,所以进入InitTargetPlatform(TARGET_SENSORTILE)函数。
- Sensor_IO_SPI_CS_Init_All(); //初始化stm32与所有传感器的通讯引脚
- #ifdef OSX_BMS_ENABLE_PRINTF //判断是否使能串口打印
- /* enable USB power on Pwrctrl CR2 register */
- HAL_PWREx_EnableVddUSB();
- /* Configure the CDC */
- /* Init Device Library */
- USBD_Init(&USBD_Device, &VCP_Desc, 0); //串口初始化
- /* Add Supported Class */
- USBD_RegisterClass(&USBD_Device, USBD_CDC_CLASS);
- /* Add Interface callbacks for AUDIO and CDC Class */
- USBD_CDC_RegisterInterface(&USBD_Device, &USBD_CDC_fops);
- /* Start Device Process */
- USBD_Start(&USBD_Device);
- /* 10 seconds ... for having time to open the Terminal
- * for looking the BlueMicrosystem Initialization phase */
- HAL_Delay(10000);
复制代码
接下来初始化LED灯GPIO口,BSP_LED_Init( LED1 );可以跳转到该函数看下:
- void BSP_LED_Init(Led_TypeDef Led)
- {
- GPIO_InitTypeDef GPIO_InitStruct;
- /* Enable VddIO2 for GPIOG */
- __HAL_RCC_PWR_CLK_ENABLE();
- HAL_PWREx_EnableVddIO2();
- /* Enable the GPIO_LED clock */
- LEDx_GPIO_CLK_ENABLE(Led);
- /* Configure the GPIO_LED pin */
- GPIO_InitStruct.Pin = GPIO_PIN[Led];
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
- HAL_GPIO_Init(GPIO_PORT[Led], &GPIO_InitStruct);
- }
复制代码
接下来就是初始化所有传感器(173行):
- /* Reset all the Target's Features */
- memset(&TargetBoardFeatures, 0, sizeof(TargetFeatures_t));
- /* Discovery and Intialize all the MEMS Target's Features */
- Init_MEM1_Sensors();
复制代码
然后判断是否接电池,是的话初始化电池检测芯片:
- #ifdef STM32_SENSORTILE
- /* Inialize the Gas Gouge if the battery is present */
- if(BSP_GG_Init(&TargetBoardFeatures.HandleGGComponent) == COMPONENT_OK){
- OSX_BMS_PRINTF("OK Gas Gouge Component\n\r");
- } else {
- OSX_BMS_PRINTF("Battery not present\n\r");
- }
复制代码
到此InitTargetPlatform函数基本已经执行完毕了,接下来回到main函数,执行InitMetaDataManager函数:
- InitMetaDataManager((void *)known_OsxLic,MDM_DATA_TYPE_LIC,NULL);
复制代码
该函数本人理解为初始化数据算法的初始化(不知是否理解有误),然后后面的代码就是判断是否有某种算法然后使能加载算法的功能了:
- {
- int32_t Index=0;
- while(known_OsxLic[Index].LicEnum!=OSX_END) {
- MDM_PayLoadLic_t *PayLoad = (MDM_PayLoadLic_t *) MDM_LicTable[known_OsxLic[Index].LicEnum].Address;
- if(PayLoad->osxLicenseInitialized) {
- switch(known_OsxLic[Index].LicEnum) {
- /* Code for MotionFX integration - Start Section */
- case OSX_MOTION_FX: //osxMotionFX (iNEMOEngine PRO) 实时的运动数据传感器融合
- MCR_OSX_COPY_LICENSE_FROM_MDM(osx_mfx_license,PayLoad->osxLicense);
- MotionFX_License_init(PayLoad);
- break;
- /* Code for MotionFX integration - End Section */
- /* Code for MotionAR integration - Start Section */
- case OSX_MOTION_AR: //osxMotionAR (iNEMOEngine PRO) 提供实时的运动姿态是识别 (OPEN.MEMS license)
- MCR_OSX_COPY_LICENSE_FROM_MDM(osx_mar_license,PayLoad->osxLicense);
- MotionAR_License_init(PayLoad);
- break;
- /* Code for MotionAR integration - End Section */
- /* Code for MotionCP integration - Start Section */
- case OSX_MOTION_CP: //osxMotionCP (iNEMOEngine PRO) 提供穿戴位置识别
- MCR_OSX_COPY_LICENSE_FROM_MDM(osx_mcp_license,PayLoad->osxLicense);
- MotionCP_License_init(PayLoad);
- break;
- /* Code for MotionCP integration - End Section */
- /* Code for MotionGR integration - Start Section */
- case OSX_MOTION_GR: //osxMotionGR (iNEMOEngine PRO) 提供手势识别
- MCR_OSX_COPY_LICENSE_FROM_MDM(osx_mgr_license,PayLoad->osxLicense);
- MotionGR_License_init(PayLoad);
- break;
- /* Code for MotionGR integration - End Section */
- .......
- }
复制代码
虽然阅读了该算法库,但好像没什么收获,我还是不知道数据从哪获取,又存放于何处,就是说我还是无法利用sersontile的数据。。。
通过逛论坛我进一步得知了想利用硬件,想利用数据得看en.stsw-stlkt01固件库,好吧,看了这么就还是白费功夫。。。不过也不能说是白费功夫,至少对我理解另一个固件库有很大的帮助,还是有收获的。
2.DataLog固件库
en.stsw-stlkt01固件库里面有三个文件,我查看了DataLog固件库,因为我最主要的是获取传感器数据。
还是从main函数看起:
首先还是一初始化函数:
- HAL_Init();
- /* Configure the system clock */
- SystemClock_Config();
- if(SendOverUSB) //此例程 SendOverUSB 宏定义为1
- {
- /* Initialize LED */
- BSP_LED_Init(LED1); //LED灯GPIO的初始化
- BSP_LED_On(LED1); //LED灯亮
- }
- else
- {
- /* Initialize LEDSWD: Cannot be used during debug because it overrides SWDCLK pin configuration */
- BSP_LED_Init(LEDSWD);
- BSP_LED_Off(LEDSWD);
- }
- RTC_Config();
- RTC_TimeStampConfig();
- 然后使能USB并做相应配置:
- HAL_PWREx_EnableVddUSB();
- if(SendOverUSB) /* Configure the USB */
- {
- /*** USB CDC Configuration ***/
- /* Init Device Library */
- USBD_Init(&USBD_Device, &VCP_Desc, 0);
- /* Add Supported Class */
- USBD_RegisterClass(&USBD_Device, USBD_CDC_CLASS);
- /* Add Interface callbacks for AUDIO and CDC Class */
- USBD_CDC_RegisterInterface(&USBD_Device, &USBD_CDC_fops);
- /* Start Device Process */
- USBD_Start(&USBD_Device);
- }
- else /* Configure the SDCard */ // 若sendoverUSB = 0 则进行SD传输存储的初始化
- {
- DATALOG_SD_Init();
- }
- 初始化各个传感器的通讯配置,并使能所有传感器:
- /* Configure and disable all the Chip Select pins */
- Sensor_IO_SPI_CS_Init_All();
- /* Initialize and Enable the available sensors */
- initializeAllSensors();
- enableAllSensors();
复制代码
接下来进入一个while(1)循环:
- while (1)
- {
- /* Get sysTick value and check if it's time to execute the task */
- msTick = HAL_GetTick();
- if(msTick % DATA_PERIOD_MS == 0 && msTickPrev != msTick)
- {
- msTickPrev = msTick;
- if(SendOverUSB)
- {
- BSP_LED_On(LED1);
- }
- #ifdef NOT_DEBUGGING
- else if (SD_Log_Enabled)
- {
- BSP_LED_On(LEDSWD);
- }
- #endif
- RTC_Handler( &RtcHandle );
- Accelero_Sensor_Handler( LSM6DSM_X_0_handle );
- Gyro_Sensor_Handler( LSM6DSM_G_0_handle );
- Magneto_Sensor_Handler( LSM303AGR_M_0_handle );
- Pressure_Sensor_Handler( LPS22HB_P_0_handle );
- if(!no_T_HTS221)
- {
- Temperature_Sensor_Handler( HTS221_T_0_handle );
- }
- if(!no_H_HTS221)
- {
- Humidity_Sensor_Handler( HTS221_H_0_handle );
- }
- if(!no_GG)
- {
- Gas_Gauge_Handler(GG_handle);
- }
- ......
- }
复制代码
while循环里面有各个传感器的数值传送函数,我们可以打开其中一个,例如Accelero_Sensor_Handler( LSM6DSM_X_0_handle )函数
- void Accelero_Sensor_Handler( void *handle )
- {
- uint8_t who_am_i;
- float odr;
- float fullScale;
- uint8_t id;
- SensorAxes_t acceleration;
- uint8_t status;
- int32_t d1, d2;
- BSP_ACCELERO_Get_Instance( handle, &id );
- BSP_ACCELERO_IsInitialized( handle, &status );
- if ( status == 1 )
- {
- if ( BSP_ACCELERO_Get_Axes( handle, &acceleration ) == COMPONENT_ERROR )
- {
- acceleration.AXIS_X = 0;
- acceleration.AXIS_Y = 0;
- acceleration.AXIS_Z = 0;
- }
- if(SendOverUSB) /* Write data on the USB */
- {
- sprintf( dataOut, "\n\rACC_X: %d, ACC_Y: %d, ACC_Z: %d", (int)acceleration.AXIS_X, (int)acceleration.AXIS_Y, (int)acceleration.AXIS_Z ); //发送数据至USB串口
- CDC_Fill_Buffer(( uint8_t * )dataOut, strlen( dataOut ));
- if ( verbose == 1 ) //例程设置为0,即下面程序均不执行
- {
- if ( BSP_ACCELERO_Get_WhoAmI( handle, &who_am_i ) == COMPONENT_ERROR )
- {
- sprintf( dataOut, "WHO AM I address[%d]: ERROR\n", id );
- }
- else
- {
- sprintf( dataOut, "WHO AM I address[%d]: 0x%02X\n", id, who_am_i );
- }
- CDC_Fill_Buffer(( uint8_t * )dataOut, strlen( dataOut ));
- if ( BSP_ACCELERO_Get_ODR( handle, &odr ) == COMPONENT_ERROR )
- {
- sprintf( dataOut, "ODR[%d]: ERROR\n", id );
- }
- else
- {
- floatToInt( odr, &d1, &d2, 3 );
- sprintf( dataOut, "ODR[%d]: %d.%03d Hz\n", (int)id, (int)d1, (int)d2 );
- }
- CDC_Fill_Buffer(( uint8_t * )dataOut, strlen( dataOut ));
- if ( BSP_ACCELERO_Get_FS( handle, &fullScale ) == COMPONENT_ERROR )
- {
- sprintf( dataOut, "FS[%d]: ERROR\n", id );
- }
- else
- {
- floatToInt( fullScale, &d1, &d2, 3 );
- sprintf( dataOut, "FS[%d]: %d.%03d g\n", (int)id, (int)d1, (int)d2 );
- }
- CDC_Fill_Buffer(( uint8_t * )dataOut, strlen( dataOut ));
- }
- }
- else if(SD_Log_Enabled) /* Write data to the file on the SDCard */
- {
- uint8_t size;
- size = sprintf(dataOut, "%d\t%d\t%d\t", (int)acceleration.AXIS_X, (int)acceleration.AXIS_Y, (int)acceleration.AXIS_Z);
- res = f_write(&MyFile, dataOut, size, (void *)&byteswritten);
- }
- }
- }
复制代码
通过跳转至该函数我们得知数据是放在哪里,例如加速度计三轴的数值 x=(int)acceleration.AXIS_X, y=(int)acceleration.AXIS_Y,
z=(int)acceleration.AXIS_Z,,其他传感器的数值存放也是一样可以查看。
通过USB串口连接电脑,装好驱动,打开串口助手,我们可以看到各个传感器的数值,不过我看不到温湿度的数值,打印出来的温湿度数值均为0,也不知道是什么原因,查看了代码好像也已经初始化了。。。望坛友门能帮忙解决本菜鸟的疑惑,谢谢。
|
|