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@9:cb7fe3e130fc, 2019-09-08 (annotated)
- Committer:
- stillChris
- Date:
- Sun Sep 08 04:04:49 2019 +0000
- Revision:
- 9:cb7fe3e130fc
- Parent:
- 8:2a542bbf7bb7
Clean build, exception MBED_RAM_SIZE redefinition
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 | 6:8b9d7b40fbbf | 37 | //#define SINGLE_STEP_SPI_WRITE |
stillChris | 6:8b9d7b40fbbf | 38 | //#define SINGLE_STEP_SPI_READ |
stillChris | 7:527bcafe93df | 39 | #define ESHD_FRAM_TEST_ERROR_INSERT 0 //set one bit in the ESHD_FRAM_TEST_ERROR_INSERT byte to intentionally induce write errors |
stillChris | 3:c8b1679fa467 | 40 | |
stillChris | 0:f19cfceb5f7b | 41 | int ESHD_testFram(int addrOffset, int addrRange, int testMode) |
stillChris | 0:f19cfceb5f7b | 42 | { |
stillChris | 0:f19cfceb5f7b | 43 | int testData=0; |
stillChris | 0:f19cfceb5f7b | 44 | int testAddr=0; |
stillChris | 0:f19cfceb5f7b | 45 | int rtnVal = 0; |
stillChris | 0:f19cfceb5f7b | 46 | |
stillChris | 0:f19cfceb5f7b | 47 | printf("\nFRAM test Utility\n"); |
stillChris | 8:2a542bbf7bb7 | 48 | printf("~~~~~~~~~~~~~~~~~\n\n"); |
stillChris | 0:f19cfceb5f7b | 49 | hFram.Init(); |
stillChris | 0:f19cfceb5f7b | 50 | printf("\nFRAM Fill Memory\n"); |
stillChris | 0:f19cfceb5f7b | 51 | |
stillChris | 0:f19cfceb5f7b | 52 | for(testAddr=0; testAddr<addrRange; testAddr++) |
stillChris | 0:f19cfceb5f7b | 53 | { |
stillChris | 6:8b9d7b40fbbf | 54 | testData = ESHD_FRAM_TEST_DATA | ESHD_FRAM_TEST_ERROR_INSERT; |
stillChris | 0:f19cfceb5f7b | 55 | //fill byte by byte |
stillChris | 0:f19cfceb5f7b | 56 | hFram.write(testAddr, (char)testData); |
stillChris | 3:c8b1679fa467 | 57 | #ifdef SINGLE_STEP_SPI_WRITE |
stillChris | 3:c8b1679fa467 | 58 | int step; |
stillChris | 6:8b9d7b40fbbf | 59 | cin >> step; |
stillChris | 3:c8b1679fa467 | 60 | #endif |
stillChris | 0:f19cfceb5f7b | 61 | } |
stillChris | 7:527bcafe93df | 62 | printf("\nFRAM Read-Check\n"); |
stillChris | 6:8b9d7b40fbbf | 63 | |
stillChris | 0:f19cfceb5f7b | 64 | for(testAddr=0; testAddr<addrRange; testAddr++) |
stillChris | 0:f19cfceb5f7b | 65 | { |
stillChris | 0:f19cfceb5f7b | 66 | testData = hFram.read(testAddr); |
stillChris | 2:4436529c3560 | 67 | if(testData != ESHD_FRAM_TEST_DATA) |
stillChris | 0:f19cfceb5f7b | 68 | { |
stillChris | 7:527bcafe93df | 69 | printf("\nFRAM test failure - memory = 0x%04x, expected value = 0x%02x, data read = 0x%02x\n\n", |
stillChris | 2:4436529c3560 | 70 | testAddr, ESHD_FRAM_TEST_DATA, testData); |
stillChris | 0:f19cfceb5f7b | 71 | rtnVal = -1; |
stillChris | 0:f19cfceb5f7b | 72 | } |
stillChris | 3:c8b1679fa467 | 73 | #ifdef SINGLE_STEP_SPI_WRITE |
stillChris | 3:c8b1679fa467 | 74 | int step; |
stillChris | 6:8b9d7b40fbbf | 75 | cin >> step; |
stillChris | 3:c8b1679fa467 | 76 | #endif |
stillChris | 0:f19cfceb5f7b | 77 | } |
stillChris | 6:8b9d7b40fbbf | 78 | printf("\nFRAM Test Complete\n"); |
stillChris | 0:f19cfceb5f7b | 79 | |
stillChris | 0:f19cfceb5f7b | 80 | return (rtnVal); |
stillChris | 0:f19cfceb5f7b | 81 | } |
stillChris | 0:f19cfceb5f7b | 82 | |
stillChris | 0:f19cfceb5f7b | 83 | |
stillChris | 0:f19cfceb5f7b | 84 | int main() |
stillChris | 0:f19cfceb5f7b | 85 | { |
stillChris | 3:c8b1679fa467 | 86 | printf("\n\nESHD Main Menu\n"); |
stillChris | 3:c8b1679fa467 | 87 | printf("~~~~~~~~~~~~~~\n\n"); |
stillChris | 3:c8b1679fa467 | 88 | |
stillChris | 3:c8b1679fa467 | 89 | #ifdef ESHD_RUN_SENSOR_LOOP |
stillChris | 0:f19cfceb5f7b | 90 | float sensor_value = 0; |
stillChris | 0:f19cfceb5f7b | 91 | int16_t pDataXYZ[3] = {0}; |
stillChris | 0:f19cfceb5f7b | 92 | float pGyroDataXYZ[3] = {0}; |
stillChris | 0:f19cfceb5f7b | 93 | |
stillChris | 0:f19cfceb5f7b | 94 | BSP_TSENSOR_Init(); |
stillChris | 0:f19cfceb5f7b | 95 | BSP_HSENSOR_Init(); |
stillChris | 0:f19cfceb5f7b | 96 | BSP_PSENSOR_Init(); |
stillChris | 0:f19cfceb5f7b | 97 | |
stillChris | 0:f19cfceb5f7b | 98 | BSP_MAGNETO_Init(); |
stillChris | 0:f19cfceb5f7b | 99 | BSP_GYRO_Init(); |
stillChris | 0:f19cfceb5f7b | 100 | BSP_ACCELERO_Init(); |
stillChris | 0:f19cfceb5f7b | 101 | |
stillChris | 0:f19cfceb5f7b | 102 | while(1) { |
stillChris | 7:527bcafe93df | 103 | printf("\n\nESHD Sensor Loop\n"); |
stillChris | 9:cb7fe3e130fc | 104 | printf("~~~~~~~~~~~~~~~~\n\n"); |
stillChris | 0:f19cfceb5f7b | 105 | |
stillChris | 3:c8b1679fa467 | 106 | led2 = 1; |
stillChris | 0:f19cfceb5f7b | 107 | |
stillChris | 0:f19cfceb5f7b | 108 | sensor_value = BSP_TSENSOR_ReadTemp(); |
stillChris | 7:527bcafe93df | 109 | printf("TEMPERATURE = %.2f degC\n", sensor_value); |
stillChris | 0:f19cfceb5f7b | 110 | |
stillChris | 0:f19cfceb5f7b | 111 | sensor_value = BSP_HSENSOR_ReadHumidity(); |
stillChris | 0:f19cfceb5f7b | 112 | printf("HUMIDITY = %.2f %%\n", sensor_value); |
stillChris | 0:f19cfceb5f7b | 113 | |
stillChris | 0:f19cfceb5f7b | 114 | sensor_value = BSP_PSENSOR_ReadPressure(); |
stillChris | 0:f19cfceb5f7b | 115 | printf("PRESSURE is = %.2f mBar\n", sensor_value); |
stillChris | 0:f19cfceb5f7b | 116 | |
stillChris | 3:c8b1679fa467 | 117 | led2 = 0; |
stillChris | 0:f19cfceb5f7b | 118 | |
stillChris | 0:f19cfceb5f7b | 119 | wait(1); |
stillChris | 0:f19cfceb5f7b | 120 | |
stillChris | 3:c8b1679fa467 | 121 | led2 = 1; |
stillChris | 0:f19cfceb5f7b | 122 | |
stillChris | 0:f19cfceb5f7b | 123 | BSP_MAGNETO_GetXYZ(pDataXYZ); |
stillChris | 0:f19cfceb5f7b | 124 | printf("\nMAGNETO_X = %d\n", pDataXYZ[0]); |
stillChris | 0:f19cfceb5f7b | 125 | printf("MAGNETO_Y = %d\n", pDataXYZ[1]); |
stillChris | 0:f19cfceb5f7b | 126 | printf("MAGNETO_Z = %d\n", pDataXYZ[2]); |
stillChris | 0:f19cfceb5f7b | 127 | |
stillChris | 0:f19cfceb5f7b | 128 | BSP_GYRO_GetXYZ(pGyroDataXYZ); |
stillChris | 0:f19cfceb5f7b | 129 | printf("\nGYRO_X = %.2f\n", pGyroDataXYZ[0]); |
stillChris | 0:f19cfceb5f7b | 130 | printf("GYRO_Y = %.2f\n", pGyroDataXYZ[1]); |
stillChris | 0:f19cfceb5f7b | 131 | printf("GYRO_Z = %.2f\n", pGyroDataXYZ[2]); |
stillChris | 0:f19cfceb5f7b | 132 | |
stillChris | 0:f19cfceb5f7b | 133 | BSP_ACCELERO_AccGetXYZ(pDataXYZ); |
stillChris | 0:f19cfceb5f7b | 134 | printf("\nACCELERO_X = %d\n", pDataXYZ[0]); |
stillChris | 0:f19cfceb5f7b | 135 | printf("ACCELERO_Y = %d\n", pDataXYZ[1]); |
stillChris | 0:f19cfceb5f7b | 136 | printf("ACCELERO_Z = %d\n", pDataXYZ[2]); |
stillChris | 0:f19cfceb5f7b | 137 | |
stillChris | 3:c8b1679fa467 | 138 | led2 = 0; |
stillChris | 3:c8b1679fa467 | 139 | #else |
stillChris | 3:c8b1679fa467 | 140 | //Always run testFram() |
stillChris | 3:c8b1679fa467 | 141 | while(1) { |
stillChris | 3:c8b1679fa467 | 142 | #endif //ESHD_RUN_SENSOR_LOOP |
stillChris | 0:f19cfceb5f7b | 143 | |
stillChris | 6:8b9d7b40fbbf | 144 | ESHD_testFram(0, ESHD_FRAM_NUM_BYTES, 1); |
stillChris | 0:f19cfceb5f7b | 145 | |
stillChris | 0:f19cfceb5f7b | 146 | wait(1); |
stillChris | 0:f19cfceb5f7b | 147 | } |
stillChris | 3:c8b1679fa467 | 148 | |
stillChris | 0:f19cfceb5f7b | 149 | } |