Initial integration of: MB85RSxx_SPI FRAM driver HelloWorld_ST_Sensors sensor classes ESHD FRAM test code (not tested - compile/build verification only)
Dependencies: mbed LPS22HB LSM6DSL MB85RSxx_SPI LSM303AGR HTS221 LIS3MDL BSP_B-L475E-IOT01
main.cpp@5:2c32c3af8599, 2019-08-30 (annotated)
- Committer:
- stillChris
- Date:
- Fri Aug 30 07:07:24 2019 +0000
- Revision:
- 5:2c32c3af8599
- Parent:
- 3:c8b1679fa467
- Child:
- 6:8b9d7b40fbbf
fixed led2 toggle logic
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
stillChris | 3:c8b1679fa467 | 1 | #include <iostream> |
stillChris | 0:f19cfceb5f7b | 2 | #include "mbed.h" |
stillChris | 0:f19cfceb5f7b | 3 | |
stillChris | 0:f19cfceb5f7b | 4 | // Sensors drivers present in the BSP library |
stillChris | 0:f19cfceb5f7b | 5 | #include "stm32l475e_iot01_tsensor.h" |
stillChris | 0:f19cfceb5f7b | 6 | #include "stm32l475e_iot01_hsensor.h" |
stillChris | 0:f19cfceb5f7b | 7 | #include "stm32l475e_iot01_psensor.h" |
stillChris | 0:f19cfceb5f7b | 8 | #include "stm32l475e_iot01_magneto.h" |
stillChris | 0:f19cfceb5f7b | 9 | #include "stm32l475e_iot01_gyro.h" |
stillChris | 0:f19cfceb5f7b | 10 | #include "stm32l475e_iot01_accelero.h" |
stillChris | 0:f19cfceb5f7b | 11 | #include "MB85RSxx_SPI.h" |
stillChris | 0:f19cfceb5f7b | 12 | |
stillChris | 3:c8b1679fa467 | 13 | //DigitalOut led1(LED1); //toggles as part of the main sensor loop |
stillChris | 0:f19cfceb5f7b | 14 | DigitalOut led2(LED2); //toggles during FRAM test |
stillChris | 0:f19cfceb5f7b | 15 | |
stillChris | 0:f19cfceb5f7b | 16 | //reference definition: MB85RSxx_SPI(PinName mosi, PinName miso, PinName sclk, PinName nss); |
stillChris | 0:f19cfceb5f7b | 17 | //warning: code requires a single valid hFram definition - no error checking in place. |
stillChris | 3:c8b1679fa467 | 18 | #define ESHD_FRAM_SPI1 |
stillChris | 0:f19cfceb5f7b | 19 | |
stillChris | 0:f19cfceb5f7b | 20 | #ifdef ESHD_FRAM_SPI1 //SPI1 pin definition: Arduino connector CN1, MB1297, RevD |
stillChris | 1:f6f0b501542a | 21 | MB85RSxx_SPI hFram(PA_7, PA_6, PA_5, PA_2); |
stillChris | 0:f19cfceb5f7b | 22 | #endif |
stillChris | 0:f19cfceb5f7b | 23 | |
stillChris | 0:f19cfceb5f7b | 24 | #ifdef ESHD_FRAM_SPI2 //SPI2 pin definition: PMOD connector CN10, MB1297, RevD |
stillChris | 1:f6f0b501542a | 25 | MB85RSxx_SPI hFram(PD_4, PD_3, PD_1, PD_5); |
stillChris | 0:f19cfceb5f7b | 26 | #endif |
stillChris | 0:f19cfceb5f7b | 27 | |
stillChris | 0:f19cfceb5f7b | 28 | #ifdef ESHD_FRAM_SPI3 //SPI3 pin definition: No external interface on MB1297, RevD |
stillChris | 1:f6f0b501542a | 29 | MB85RSxx_SPI hFram(PC_12, PC_11, PC_10, PC_9); |
stillChris | 0:f19cfceb5f7b | 30 | #endif |
stillChris | 0:f19cfceb5f7b | 31 | |
stillChris | 0:f19cfceb5f7b | 32 | #define ESHD_FRAM_NUM_BYTES (8 * 1024) //8KBytes |
stillChris | 0:f19cfceb5f7b | 33 | |
stillChris | 0:f19cfceb5f7b | 34 | #define ESHD_FRAM_TEST_DATA ((testAddr * 0x51)&0xff) |
stillChris | 0:f19cfceb5f7b | 35 | |
stillChris | 3:c8b1679fa467 | 36 | #define ESHD_RUN_SENSOR_LOOP |
stillChris | 3:c8b1679fa467 | 37 | |
stillChris | 0:f19cfceb5f7b | 38 | int ESHD_testFram(int addrOffset, int addrRange, int testMode) |
stillChris | 0:f19cfceb5f7b | 39 | { |
stillChris | 0:f19cfceb5f7b | 40 | int testData=0; |
stillChris | 0:f19cfceb5f7b | 41 | int testAddr=0; |
stillChris | 0:f19cfceb5f7b | 42 | int rtnVal = 0; |
stillChris | 0:f19cfceb5f7b | 43 | |
stillChris | 0:f19cfceb5f7b | 44 | printf("\nFRAM test Utility\n"); |
stillChris | 0:f19cfceb5f7b | 45 | hFram.Init(); |
stillChris | 0:f19cfceb5f7b | 46 | printf("\nFRAM Fill Memory\n"); |
stillChris | 0:f19cfceb5f7b | 47 | |
stillChris | 0:f19cfceb5f7b | 48 | for(testAddr=0; testAddr<addrRange; testAddr++) |
stillChris | 0:f19cfceb5f7b | 49 | { |
stillChris | 0:f19cfceb5f7b | 50 | testData = 0;//ESHD_FRAM_TEST_DATA; |
stillChris | 0:f19cfceb5f7b | 51 | //fill byte by byte |
stillChris | 0:f19cfceb5f7b | 52 | hFram.write(testAddr, (char)testData); |
stillChris | 5:2c32c3af8599 | 53 | if(testAddr&0xff==0)//Each 256 bytes |
stillChris | 0:f19cfceb5f7b | 54 | { |
stillChris | 0:f19cfceb5f7b | 55 | printf("."); //Print "." to the UART each 512 bytes |
stillChris | 3:c8b1679fa467 | 56 | led2=!led2; //Toggle LED2 |
stillChris | 0:f19cfceb5f7b | 57 | } |
stillChris | 3:c8b1679fa467 | 58 | #ifdef SINGLE_STEP_SPI_WRITE |
stillChris | 3:c8b1679fa467 | 59 | int step; |
stillChris | 3:c8b1679fa467 | 60 | cin > step; |
stillChris | 3:c8b1679fa467 | 61 | #endif |
stillChris | 0:f19cfceb5f7b | 62 | } |
stillChris | 0:f19cfceb5f7b | 63 | for(testAddr=0; testAddr<addrRange; testAddr++) |
stillChris | 0:f19cfceb5f7b | 64 | { |
stillChris | 0:f19cfceb5f7b | 65 | testData = hFram.read(testAddr); |
stillChris | 5:2c32c3af8599 | 66 | if(testAddr&0xff==0)//Each 256 bytes |
stillChris | 0:f19cfceb5f7b | 67 | { |
stillChris | 0:f19cfceb5f7b | 68 | printf("."); //Print "." to the UART |
stillChris | 3:c8b1679fa467 | 69 | led2=!led2; //Toggle LED2 |
stillChris | 0:f19cfceb5f7b | 70 | } |
stillChris | 2:4436529c3560 | 71 | if(testData != ESHD_FRAM_TEST_DATA) |
stillChris | 0:f19cfceb5f7b | 72 | { |
stillChris | 2:4436529c3560 | 73 | |
stillChris | 2:4436529c3560 | 74 | printf("\nFRAM test failure - memory = 0x%04x, expected value = 0x%02x, data read = 0x%02x\n\n", |
stillChris | 2:4436529c3560 | 75 | testAddr, ESHD_FRAM_TEST_DATA, testData); |
stillChris | 0:f19cfceb5f7b | 76 | rtnVal = -1; |
stillChris | 0:f19cfceb5f7b | 77 | } |
stillChris | 3:c8b1679fa467 | 78 | #ifdef SINGLE_STEP_SPI_WRITE |
stillChris | 3:c8b1679fa467 | 79 | int step; |
stillChris | 3:c8b1679fa467 | 80 | cin > step; |
stillChris | 3:c8b1679fa467 | 81 | #endif |
stillChris | 0:f19cfceb5f7b | 82 | } |
stillChris | 0:f19cfceb5f7b | 83 | |
stillChris | 0:f19cfceb5f7b | 84 | printf("FRAM Test Complete\n"); |
stillChris | 0:f19cfceb5f7b | 85 | |
stillChris | 0:f19cfceb5f7b | 86 | return (rtnVal); |
stillChris | 0:f19cfceb5f7b | 87 | } |
stillChris | 0:f19cfceb5f7b | 88 | |
stillChris | 0:f19cfceb5f7b | 89 | |
stillChris | 0:f19cfceb5f7b | 90 | int main() |
stillChris | 0:f19cfceb5f7b | 91 | { |
stillChris | 3:c8b1679fa467 | 92 | printf("\n\nESHD Main Menu\n"); |
stillChris | 3:c8b1679fa467 | 93 | printf("~~~~~~~~~~~~~~\n\n"); |
stillChris | 3:c8b1679fa467 | 94 | ESHD_testFram(0, ESHD_FRAM_NUM_BYTES/64, 1); |
stillChris | 3:c8b1679fa467 | 95 | |
stillChris | 3:c8b1679fa467 | 96 | #ifdef ESHD_RUN_SENSOR_LOOP |
stillChris | 0:f19cfceb5f7b | 97 | float sensor_value = 0; |
stillChris | 0:f19cfceb5f7b | 98 | int16_t pDataXYZ[3] = {0}; |
stillChris | 0:f19cfceb5f7b | 99 | float pGyroDataXYZ[3] = {0}; |
stillChris | 0:f19cfceb5f7b | 100 | |
stillChris | 0:f19cfceb5f7b | 101 | BSP_TSENSOR_Init(); |
stillChris | 0:f19cfceb5f7b | 102 | BSP_HSENSOR_Init(); |
stillChris | 0:f19cfceb5f7b | 103 | BSP_PSENSOR_Init(); |
stillChris | 0:f19cfceb5f7b | 104 | |
stillChris | 0:f19cfceb5f7b | 105 | BSP_MAGNETO_Init(); |
stillChris | 0:f19cfceb5f7b | 106 | BSP_GYRO_Init(); |
stillChris | 0:f19cfceb5f7b | 107 | BSP_ACCELERO_Init(); |
stillChris | 0:f19cfceb5f7b | 108 | |
stillChris | 0:f19cfceb5f7b | 109 | while(1) { |
stillChris | 0:f19cfceb5f7b | 110 | |
stillChris | 3:c8b1679fa467 | 111 | led2 = 1; |
stillChris | 0:f19cfceb5f7b | 112 | |
stillChris | 0:f19cfceb5f7b | 113 | sensor_value = BSP_TSENSOR_ReadTemp(); |
stillChris | 0:f19cfceb5f7b | 114 | printf("\nTEMPERATURE = %.2f degC\n", sensor_value); |
stillChris | 0:f19cfceb5f7b | 115 | |
stillChris | 0:f19cfceb5f7b | 116 | sensor_value = BSP_HSENSOR_ReadHumidity(); |
stillChris | 0:f19cfceb5f7b | 117 | printf("HUMIDITY = %.2f %%\n", sensor_value); |
stillChris | 0:f19cfceb5f7b | 118 | |
stillChris | 0:f19cfceb5f7b | 119 | sensor_value = BSP_PSENSOR_ReadPressure(); |
stillChris | 0:f19cfceb5f7b | 120 | printf("PRESSURE is = %.2f mBar\n", sensor_value); |
stillChris | 0:f19cfceb5f7b | 121 | |
stillChris | 3:c8b1679fa467 | 122 | led2 = 0; |
stillChris | 0:f19cfceb5f7b | 123 | |
stillChris | 0:f19cfceb5f7b | 124 | wait(1); |
stillChris | 0:f19cfceb5f7b | 125 | |
stillChris | 3:c8b1679fa467 | 126 | led2 = 1; |
stillChris | 0:f19cfceb5f7b | 127 | |
stillChris | 0:f19cfceb5f7b | 128 | BSP_MAGNETO_GetXYZ(pDataXYZ); |
stillChris | 0:f19cfceb5f7b | 129 | printf("\nMAGNETO_X = %d\n", pDataXYZ[0]); |
stillChris | 0:f19cfceb5f7b | 130 | printf("MAGNETO_Y = %d\n", pDataXYZ[1]); |
stillChris | 0:f19cfceb5f7b | 131 | printf("MAGNETO_Z = %d\n", pDataXYZ[2]); |
stillChris | 0:f19cfceb5f7b | 132 | |
stillChris | 0:f19cfceb5f7b | 133 | BSP_GYRO_GetXYZ(pGyroDataXYZ); |
stillChris | 0:f19cfceb5f7b | 134 | printf("\nGYRO_X = %.2f\n", pGyroDataXYZ[0]); |
stillChris | 0:f19cfceb5f7b | 135 | printf("GYRO_Y = %.2f\n", pGyroDataXYZ[1]); |
stillChris | 0:f19cfceb5f7b | 136 | printf("GYRO_Z = %.2f\n", pGyroDataXYZ[2]); |
stillChris | 0:f19cfceb5f7b | 137 | |
stillChris | 0:f19cfceb5f7b | 138 | BSP_ACCELERO_AccGetXYZ(pDataXYZ); |
stillChris | 0:f19cfceb5f7b | 139 | printf("\nACCELERO_X = %d\n", pDataXYZ[0]); |
stillChris | 0:f19cfceb5f7b | 140 | printf("ACCELERO_Y = %d\n", pDataXYZ[1]); |
stillChris | 0:f19cfceb5f7b | 141 | printf("ACCELERO_Z = %d\n", pDataXYZ[2]); |
stillChris | 0:f19cfceb5f7b | 142 | |
stillChris | 3:c8b1679fa467 | 143 | led2 = 0; |
stillChris | 3:c8b1679fa467 | 144 | #else |
stillChris | 3:c8b1679fa467 | 145 | //Always run testFram() |
stillChris | 3:c8b1679fa467 | 146 | while(1) { |
stillChris | 3:c8b1679fa467 | 147 | #endif //ESHD_RUN_SENSOR_LOOP |
stillChris | 0:f19cfceb5f7b | 148 | |
stillChris | 3:c8b1679fa467 | 149 | ESHD_testFram(0, ESHD_FRAM_NUM_BYTES/1024, 1); |
stillChris | 0:f19cfceb5f7b | 150 | |
stillChris | 0:f19cfceb5f7b | 151 | wait(1); |
stillChris | 0:f19cfceb5f7b | 152 | } |
stillChris | 3:c8b1679fa467 | 153 | |
stillChris | 0:f19cfceb5f7b | 154 | } |