/******************************************************************************* * Function Name : main. * Description : Main routine. * Input : None. * Output : None. * Return : None. *******************************************************************************/ int main(void) { boolean_t Success = TRUE; /* ================================================================ */ /* Board Initializations and Configurations except OLED */ /* (clocks, I/Os, on-chip peripherals, on-board ICs) */ /* ================================================================ */ LBF_Board_Fixed_Inits(); LBF_Board_Selective_Inits(); // actions driven by User_Configuration.h Stm32_Led_ON(); /* ================================================================ */ /* Optional initialization of Middleware libraries : */ /* USBD drivers, FatFS File System, STemWin GUI */ /* ================================================================ */ // UNCOMMENT AS NEEDED: // (refer to INFO.txt for details on actions performed) /* ... To use La BlueFrog as USB Mass Storage (Full Speed) */ // Delay_ms(1000); // Success &= LBF_LaunchUSB_MassStorage(); /* ... To initialize FatFS */ /* and mount the Data Flash as FAT File System */ // Success &= LBF_FatFS_Init(); /* ... To initialize the STemWin Graphical Library */ /* Caution: reserves some RAM - keep some for stack/heap */ Success &= LBF_emWin_Init(); // ERROR HANDLER /* Replace by your own as wished */ Led_StopNBlinkOnFalse (Success); // stops here if one of above inits has failed Stm32_Led_OFF(); /* ===================================================== */ /* Application Code Below */ /* ===================================================== */ /* == User Declarations =============================== */ uint8_t ReadValue; /* == Body ====================================================== */ OLED_Switch_ON(); // Provide power (13V) to OLED panel, enable display /* --- Check access to ALS/Proximity Sensor : ST VL6180X --- */ ReadValue = I2C2_ReadSingleReg(VL6180X_CHIPID, VL6180X_WHOAMI); if (ReadValue == VL6180X_WHOAMI_CONTENTS) { OLED_PrintString("VL6180X OK \nWHO_AM_I = "); } else { OLED_PrintString("VL6180X FAIL \nReported WHO_AM_I = "); } OLED_PrintHex(ReadValue); OLED_PrintString("\n\n"); /* --- Check access to Magnetometer : ST LIS3MDL -------- */ ReadValue = I2C2_ReadSingleReg(LIS3MDL_CHIPID, LIS3MDL_WHOAMI); if (ReadValue == LIS3MDL_WHOAMI_CONTENTS) { OLED_PrintString("LIS3MDL OK \nWHO_AM_I = "); } else { OLED_PrintString("LIS3MDL FAIL \nReported WHO_AM_I = "); } OLED_PrintHex(ReadValue); OLED_PrintString("\n\n"); /* --- Check access to Accelerometer/Gyro : ST LSM6DS3 ----- */ ReadValue = I2C2_ReadSingleReg(LSM6DS3_CHIPID, LSM6DS3_WHOAMI); if (ReadValue == LSM6DS3_WHOAMI_CONTENTS) { OLED_PrintString("LSM6DS3 OK \nWHO_AM_I = "); } else { OLED_PrintString("LSM6DS3 FAIL \nReported WHO_AM_I = "); } OLED_PrintHex(ReadValue); OLED_PrintString("\n\n"); /* --- Check access to Pressure/Temp Sensor : ST LPS25H ----- */ ReadValue = I2C2_ReadSingleReg(LPS25H_CHIPID, LPS25H_WHOAMI); if (ReadValue == LPS25H_WHOAMI_CONTENTS) { OLED_PrintString("LPS25H OK \nWHO_AM_I = "); } else { OLED_PrintString("LPS25H FAIL \nReported WHO_AM_I = "); } OLED_PrintHex(ReadValue); OLED_PrintString("\n\n"); while(1); }
/******************************************************************************* * Function Name : main. * Description : Main routine. * Input : None. * Output : None. * Return : None. *******************************************************************************/ int main(void) { boolean_t Success = TRUE; /* ================================================================ */ /* Board Initializations and Configurations except OLED */ /* (clocks, I/Os, on-chip peripherals, on-board ICs) */ /* ================================================================ */ LBF_Board_Fixed_Inits(); LBF_Board_Selective_Inits(); // actions driven by User_Configuration.h Stm32_Led_ON(); /* ================================================================ */ /* Optional initialization of Middleware libraries : */ /* USBD drivers, FatFS File System, STemWin GUI */ /* ================================================================ */ // UNCOMMENT AS NEEDED: // (refer to INFO.txt for details on actions performed) /* ... To use La BlueFrog as USB Mass Storage (Full Speed) */ // Delay_ms(1000); // Success &= LBF_LaunchUSB_MassStorage(); /* ... To initialize FatFS */ /* and mount the Data Flash as FAT File System */ // Success &= LBF_FatFS_Init(); /* ... To initialize the STemWin Graphical Library */ /* Caution: reserves some RAM - keep some for stack/heap */ Success &= LBF_emWin_Init(); // ERROR HANDLER /* Replace by your own as wished */ Led_StopNBlinkOnFalse (Success); // stops here if one of above inits has failed Stm32_Led_OFF(); /* ===================================================== */ /* Application Code Below */ /* ===================================================== */ /* == User Declarations =============================== */ void Get_ZeroGauss_OffsetXY( int16_t* pMField_X_Raw_Offset, int16_t* pMField_Y_Raw_Offset ); void Get_Magnetic_FieldXY( int16_t MField_X_Raw_Offset, int16_t MField_Y_Raw_Offset, int16_t* pMField_X_mGauss, int16_t* pMField_Y_mGauss); uint8_t ReadValue; int16_t MField_X_Raw_Offset, MField_Y_Raw_Offset ; int16_t MField_X_mGauss, MField_Y_mGauss; int32_t MField_X_mGauss_2 =0, MField_Y_mGauss_2 =0; int32_t MField_X_mGauss_1 =0, MField_Y_mGauss_1 =0; int32_t MField_X_mGauss_Filtd, MField_Y_mGauss_Filtd; int32_t Field_Magnitude; int32_t X_Gfx_Vector, Y_Gfx_Vector; int32_t X_Previous_Gfx_Vector = 0, Y_Previous_Gfx_Vector=0; #define MGAUSS_MAX 450 //Max expected magnitude of magnetic field to display #define BKGND_COLOR 0x102020 // dark grey #define FOREGND_COLOR 0x00AAA0 // blue-green /* == Body ====================================================== */ OLED_Switch_ON(); // Provide power (13V) to OLED panel, enable display /* --- Check access to Magnetometer : ST LIS3MDL -------- */ ReadValue = I2C2_ReadSingleReg(LIS3MDL_CHIPID, LIS3MDL_WHOAMI); Led_StopNBlinkOnFalse ( ReadValue == LIS3MDL_WHOAMI_CONTENTS ); /* --- Configure Magnetometer -------------------------- */ // Define Full Scale: Reg. CTRL_REG2 @0x21 // NB- earth magnetic field magnitude = 0.25 to 0.65 Gauss I2C2_WriteSingleReg(LIS3MDL_CHIPID, 0x21, 0x00); // FS = 4 Gauss // Define XY Performance mode and ODR: Reg. CTRL_REG1 @0x20 I2C2_WriteSingleReg(LIS3MDL_CHIPID, 0x20, 0x90); // 0b10010000 // Enable T° sensor // Low-power mode on X and Y // ODR = 10Hz // Define Z Performance mode: Reg. CTRL_REG4 @0x23 I2C2_WriteSingleReg(LIS3MDL_CHIPID, 0x23, 0x00); // 0b00000000 // Calibrate to compensate Zero Gauss Offset Get_ZeroGauss_OffsetXY( &MField_X_Raw_Offset, &MField_Y_Raw_Offset ); /* --- Prepare Display of Results -------------------------- */ GUI_SetFont(&GUI_Font24B_ASCII); GUI_SetTextMode(GUI_TM_TRANS); GUI_SetColor(BKGND_COLOR); GUI_FillRect(0, 0, X_FULL_SCREEN-1, Y_FULL_SCREEN-1); GUI_SetColor(0xAAAA00); GUI_DrawCircle(Y_FULL_SCREEN/2, Y_FULL_SCREEN/2, (Y_FULL_SCREEN/2)-10); GUI_FillCircle(Y_FULL_SCREEN/2, Y_FULL_SCREEN/2, 2); /* --- Start Tracking Magnetic Field -------------------------- */ while(1) { // --- Capture :------------------------------------------------ // SINGLE SHOT conversion : CTRL_REG3 @0x22 : I2C2_WriteSingleReg(LIS3MDL_CHIPID, 0x22, 0x01); // 0b00000001 // Wait until data available from Magnetometer do { ReadValue = I2C2_ReadSingleReg(LIS3MDL_CHIPID, 0x27); // Status Reg } while ( (ReadValue & 0x08) != 0x08); // bit set when new XYZ data available // Read Results Get_Magnetic_FieldXY( MField_X_Raw_Offset, MField_Y_Raw_Offset, &MField_X_mGauss, &MField_Y_mGauss ); // --- Display North ------------------------------------------------ if (MField_X_mGauss > MGAUSS_MAX) MField_X_mGauss = MGAUSS_MAX; if (MField_X_mGauss < -MGAUSS_MAX) MField_X_mGauss = -MGAUSS_MAX; if (MField_Y_mGauss > MGAUSS_MAX) MField_Y_mGauss = MGAUSS_MAX; if (MField_Y_mGauss < -MGAUSS_MAX) MField_Y_mGauss = -MGAUSS_MAX; // Filtering to limit "jitter" effect on position MField_X_mGauss_Filtd = (MField_X_mGauss_2 + 2*MField_X_mGauss_1 + (int32_t)MField_X_mGauss) /4; MField_Y_mGauss_Filtd = (MField_Y_mGauss_2 + 2*MField_Y_mGauss_1 + (int32_t)MField_Y_mGauss) /4; MField_X_mGauss_2 = MField_X_mGauss_1; MField_X_mGauss_1 = (int32_t)MField_X_mGauss; MField_Y_mGauss_2 = MField_Y_mGauss_1; MField_Y_mGauss_1 = (int32_t)MField_Y_mGauss; Field_Magnitude = ( MField_X_mGauss_Filtd * MField_X_mGauss_Filtd) + ( MField_Y_mGauss_Filtd * MField_Y_mGauss_Filtd); X_Gfx_Vector = ( ( MField_X_mGauss_Filtd + MGAUSS_MAX) * (Y_FULL_SCREEN-1) ) / (2*MGAUSS_MAX) ; Y_Gfx_Vector = ( (-MField_Y_mGauss_Filtd + MGAUSS_MAX) * (Y_FULL_SCREEN-1) ) / (2*MGAUSS_MAX) ; // Only Y_FULL_SCREEN to avoid distorsion due to shape of screen // Compensate for size of letter "N" displayed as its x,y correspond to top left corner X_Gfx_Vector -= 6; Y_Gfx_Vector -= 12; // Skip Display if vector falls out of range if (Field_Magnitude < MGAUSS_MAX*MGAUSS_MAX ) { if ( (X_Gfx_Vector != X_Previous_Gfx_Vector) || (Y_Gfx_Vector != Y_Previous_Gfx_Vector) ) // Redraw only if needed { // Erase Previous GUI_SetColor( BKGND_COLOR ); GUI_DispStringAt("N", X_Previous_Gfx_Vector, Y_Previous_Gfx_Vector); // Draw New GUI_SetColor( FOREGND_COLOR ); GUI_DispStringAt("N", X_Gfx_Vector, Y_Gfx_Vector); X_Previous_Gfx_Vector = X_Gfx_Vector; Y_Previous_Gfx_Vector = Y_Gfx_Vector; } // end if } // end if Delay_ms(500); } // end while(1) }
/******************************************************************************* * Function Name : main. * Description : Main routine. * Input : None. * Output : None. * Return : None. *******************************************************************************/ int main(void) { boolean_t Success = TRUE; /* ================================================================ */ /* Board Initializations and Configurations except OLED */ /* (clocks, I/Os, on-chip peripherals, on-board ICs) */ /* ================================================================ */ LBF_Board_Fixed_Inits(); LBF_Board_Selective_Inits(); // actions driven by User_Configuration.h Stm32_Led_ON(); /* ================================================================ */ /* Optional initialization of Middleware libraries : */ /* USBD drivers, FatFS File System, STemWin GUI */ /* ================================================================ */ // UNCOMMENT AS NEEDED: // (refer to INFO.txt for details on actions performed) /* ... To use La BlueFrog as USB Mass Storage (Full Speed) */ // Delay_ms(1000); // Success &= LBF_LaunchUSB_MassStorage(); /* ... To initialize FatFS */ /* and mount the Data Flash as FAT File System */ // Success &= LBF_FatFS_Init(); /* ... To initialize the STemWin Graphical Library */ /* Caution: reserves some RAM - keep some for stack/heap */ //Success &= LBF_emWin_Init(); // ERROR HANDLER /* Replace by your own as wished */ Led_StopNBlinkOnFalse (Success); // stops here if one of above inits has failed Stm32_Led_OFF(); /* ===================================================== */ /* Application Code Below */ /* ===================================================== */ /* == User Declarations =============================== */ // REMINDER : // Usage of pins of extension connector as GPIO, PWM etc // to be specified in User_Configuration.h // On EXtension Connector Position 2: // Global Enable for MC33926 carrier board #define MC33926_EN_LOW() GPIO_LOW(CONN_POS2_PORT, CONN_POS2_PIN) #define MC33926_EN_HIGH() GPIO_HIGH(CONN_POS2_PORT, CONN_POS2_PIN) // On EXtension Connector Position 3: // Fault Status from MC33926, active low #define STATUS_FAULT_MC33926() IS_GPIO_RESET(CONN_POS3_PORT, CONN_POS3_PIN) // returns a uint8_t result // On Extension Connector Position 5: // Direction (Common to Motors 1 and 2) #define MC33926_DIR_BWD() GPIO_LOW(CONN_POS5_PORT, CONN_POS5_PIN) #define MC33926_DIR_FWD() GPIO_HIGH(CONN_POS5_PORT, CONN_POS5_PIN) // On Extension Connector Position 6: // notDirection (Common to Motors 1 and 2) #define MC33926_nDIR_BWD() GPIO_HIGH(CONN_POS6_PORT, CONN_POS6_PIN) #define MC33926_nDIR_FWD() GPIO_LOW(CONN_POS6_PORT, CONN_POS6_PIN) // !!!!!!!! MCU must drive both DIR and nDIR // On Extension Connector Position 9: // Enable Motor 1 - PWM signal (supports up to 20KHz) // On Extension Connector Position 10: // Enable Motor 2 - PWM signal (supports up to 20KHz) /* == Body ======================================== */ Stm32_Led_ON(); Delay_ms(2500); // Set Direction = Forward MC33926_DIR_FWD(); MC33926_nDIR_FWD(); // Enable Motor Carrier MC33926_EN_LOW(); Delay_ms(1000); MC33926_EN_HIGH(); // Turn immedialetely off if Fault, if ( STATUS_FAULT_MC33926() ) { MC33926_EN_LOW(); Led_StopNBlinkOnFalse( FALSE ); // } LBF_PWM_Start( PWM4_CH3 ); LBF_PWM_Start( PWM4_CH4 ); LBF_PWM_SetPeriod_us( PWM4, 60); // 60us period PWM = 17KHz LBF_PWM_SetPulse_us (PWM4_CH3, 30); // 30/60 = 50% duty cycle LBF_PWM_SetPulse_us (PWM4_CH4, 30); // 30/60 = 50% duty cycle while(1) { // Turn immedialetely off if Fault, if ( STATUS_FAULT_MC33926() ) { MC33926_EN_LOW(); Led_StopNBlinkOnFalse( FALSE ); // } // Run for a while and Stop Motor Delay_ms( 2000 ); // run for a while and stop LBF_PWM_SetPulse_us (PWM4_CH3, 0); LBF_PWM_SetPulse_us (PWM4_CH4, 0); Stm32_Led_ON(); Delay_ms( 2000 ); // wait for a while and restart LBF_PWM_SetPulse_us (PWM4_CH3, 30); // 30/60 = 50% duty cycle LBF_PWM_SetPulse_us (PWM4_CH4, 30); // 30/60 = 50% duty cycle Stm32_Led_OFF(); } return 0; }
/******************************************************************************* * Function Name : main. * Description : Main routine. * Input : None. * Output : None. * Return : None. *******************************************************************************/ int main(void) { boolean_t Success = TRUE; /* ================================================================ */ /* Board Initializations and Configurations except OLED */ /* (clocks, I/Os, on-chip peripherals, on-board ICs) */ /* ================================================================ */ LBF_Board_Fixed_Inits(); LBF_Board_Selective_Inits(); // actions driven by User_Configuration.h Stm32_Led_ON(); /* ================================================================ */ /* Optional initialization of Middleware libraries : */ /* USBD drivers, FatFS File System, STemWin GUI */ /* ================================================================ */ // UNCOMMENT AS NEEDED: // (refer to INFO.txt for details on actions performed) /* ... To use La BlueFrog as USB Mass Storage (Full Speed) */ //Delay_ms(1000); //Success &= LBF_LaunchUSB_MassStorage(); /* ... To initialize FatFS */ /* and mount the Data Flash as FAT File System */ Success &= LBF_FatFS_Init(); /* ... To initialize the STemWin Graphical Library */ /* Caution: reserves some RAM - keep some for stack/heap */ // Success &= LBF_emWin_Init(); // ERROR HANDLER /* Replace by your own as wished */ Led_StopNBlinkOnFalse (Success); // stops here if one of above inits has failed Stm32_Led_OFF(); /* ===================================================== */ /* Application Code Below */ /* ===================================================== */ // NOTE: Here, as Data Flash may not be formatted yet, // we don't use LBF_LaunchUSB_MassStorage in the initalization phase above /* == User Declarations =============================== */ FIL MyFile; /* FatFS File object */ UINT bw; /* Number of bytes written in file */ /* == Body ======================================== */ Stm32_Led_ON(); // Launch reformat only when any Push Button pressed while ( !State_Switch1_IsOn() && !State_Switch2_IsOn() ); Stm32_Led_OFF(); /* Create FAT volume with default cluster size */ Success &= ( f_mkfs("", 0, 0) == FR_OK); /* Create a file as new */ Success &= ( f_open(&MyFile, "FS_Formt.log", FA_CREATE_NEW | FA_WRITE) == FR_OK); /* Write a message */ Success &= ( f_write(&MyFile, "Formatted by FatFS\r\n", 20, &bw) == FR_OK); /* Close the file */ f_close(&MyFile); // Launch USB Success &= LBF_LaunchUSB_MassStorage(); /* Error handler */ Led_StopNBlinkOnFalse (Success); // Done ! Stm32_Led_ON(); while (1); }
/******************************************************************************* * Function Name : main. * Description : Main routine. * Input : None. * Output : None. * Return : None. *******************************************************************************/ int main(void) { boolean_t Success = TRUE; /* ================================================================ */ /* Board Initializations and Configurations except OLED */ /* (clocks, I/Os, on-chip peripherals, on-board ICs) */ /* ================================================================ */ LBF_Board_Fixed_Inits(); LBF_Board_Selective_Inits(); // actions driven by User_Configuration.h LBF_Led_ON(); /* ================================================================ */ /* Optional initialization of Middleware libraries : */ /* USBD drivers, FatFS File System, STemWin GUI */ /* ================================================================ */ // UNCOMMENT AS NEEDED: // (refer to INFO.txt for details on actions performed) /* ... To use La BlueFrog as USB Mass Storage (Full Speed) */ // Success &= LBF_LaunchUSB_MassStorage(); /* ... To initialize FatFS */ /* and mount the Data Flash as FAT File System */ // Success &= LBF_FatFS_Init(); /* ... To initialize the STemWin Graphical Library */ /* Caution: reserves some RAM - keep some for stack/heap */ // Success &= LBF_emWin_Init(); // ERROR HANDLER /* Replace by your own as wished */ LBF_Led_StopNBlinkOnFalse (Success); // stops here if one of above inits has failed /* ===================================================== */ /* Application Code Below */ /* ===================================================== */ // -------------------------------------------------------- // BTLE must be enabled by #define in User_Configuration.h // Name of the file containing code to download by STM32 // into BTLE module also defined there -- download occurs // during LBF_Board_Selective_Inits() phase. // This executable must be present on FAT File System on Flash // (typically stored there from PC through USB). // In this demo, code is supposed to be Serial Port Service // snippet provided by Dialog -- this configures the BTLE // to behave as UART cable replacement. Data sent to // BTLE module over UART1 at 115200 baud is transitted over BTLE // This data can be received by DSPS application running in iOS // or Android, provided by Dialog, available on Appple/Android // app stores // -------------------------------------------------------- /* == User Declarations =============================== */ char TxString[]="Bonjour toi !\nThis is La BlueFrog talking.\nHow are you ?\n"; char* pString; /* == Body ======================================== */ // Send Message(); while(1) { // Wait for user to push side-switch if ( LBF_State_Switch1_IsOn() ) { LBF_Led_ON(); // Send a test message from UART1 to BTLE for emission pString = TxString; LBF_UART_SendString_SwFlowControl( UART1, pString); while ( LBF_State_Switch1_IsOn() ); // wait for release LBF_Led_OFF(); LBF_Delay_ms(500); } } // end of while(1) }