Demo for MAX32625PICO board library
Dependencies: USBDevice max32625pico
Fork of PICO_self_test by
main.cpp@7:62efbc5411c8, 2016-12-19 (annotated)
- Committer:
- switches
- Date:
- Mon Dec 19 22:45:22 2016 +0000
- Revision:
- 7:62efbc5411c8
- Parent:
- 6:fa0134a8ac32
- Child:
- 8:26dc73d09bd9
Updated self test to use USB HID keyboard instead of USB MSD to speed up test. Added checks for micro SD card, BMI160, and button.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
switches | 0:60a522ae2e35 | 1 | #include "mbed.h" |
switches | 1:464c8b3634dc | 2 | #include "max32630fthr.h" |
switches | 7:62efbc5411c8 | 3 | #include "SDFileSystem.h" |
switches | 7:62efbc5411c8 | 4 | #include "USBKeyboard.h" |
switches | 0:60a522ae2e35 | 5 | |
switches | 6:fa0134a8ac32 | 6 | MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); |
switches | 3:7264c8044625 | 7 | |
switches | 4:1c6819a42db0 | 8 | // Hardware serial port over DAPLink |
switches | 4:1c6819a42db0 | 9 | Serial daplink(P2_1, P2_0); |
switches | 4:1c6819a42db0 | 10 | |
switches | 4:1c6819a42db0 | 11 | DigitalOut rLED(LED1, LED_ON); |
switches | 4:1c6819a42db0 | 12 | DigitalOut gLED(LED2, LED_OFF); |
switches | 4:1c6819a42db0 | 13 | DigitalOut bLED(LED3, LED_OFF); |
switches | 7:62efbc5411c8 | 14 | DigitalIn button(SW1, PullUp); |
switches | 4:1c6819a42db0 | 15 | AnalogIn monIn(AIN_0); |
switches | 4:1c6819a42db0 | 16 | AnalogIn vddbIn(AIN_6); |
switches | 4:1c6819a42db0 | 17 | AnalogIn vdd18In(AIN_7); |
switches | 4:1c6819a42db0 | 18 | AnalogIn vdd12In(AIN_8); |
switches | 4:1c6819a42db0 | 19 | AnalogIn vrtcIn(AIN_9); |
switches | 4:1c6819a42db0 | 20 | |
switches | 7:62efbc5411c8 | 21 | SDFileSystem sd(P0_5, P0_6, P0_4, P0_7, "sd"); // mosi, miso, sclk, cs |
switches | 7:62efbc5411c8 | 22 | USBKeyboard keyboard; |
switches | 7:62efbc5411c8 | 23 | |
switches | 7:62efbc5411c8 | 24 | #define BMI160_I2C_ADDR 0xD0 |
switches | 7:62efbc5411c8 | 25 | |
switches | 4:1c6819a42db0 | 26 | // Function to report failure |
switches | 4:1c6819a42db0 | 27 | void testFailed() |
switches | 4:1c6819a42db0 | 28 | { |
switches | 4:1c6819a42db0 | 29 | daplink.printf("\r\n! Test Failed !\r\n"); |
switches | 4:1c6819a42db0 | 30 | rLED = LED_ON; |
switches | 4:1c6819a42db0 | 31 | gLED = LED_OFF; |
switches | 4:1c6819a42db0 | 32 | bLED = LED_OFF; |
switches | 4:1c6819a42db0 | 33 | while(1) { |
switches | 4:1c6819a42db0 | 34 | Thread::wait(500); |
switches | 4:1c6819a42db0 | 35 | gLED = !gLED; |
switches | 7:62efbc5411c8 | 36 | } |
switches | 4:1c6819a42db0 | 37 | } |
switches | 4:1c6819a42db0 | 38 | |
switches | 4:1c6819a42db0 | 39 | // Function to read monitor port |
switches | 7:62efbc5411c8 | 40 | float readMon(MAX14690::monCfg_t monCfg) |
switches | 7:62efbc5411c8 | 41 | { |
switches | 4:1c6819a42db0 | 42 | pegasus.max14690.monSet(monCfg, MAX14690::MON_DIV4); |
switches | 4:1c6819a42db0 | 43 | Thread::wait(5); |
switches | 7:62efbc5411c8 | 44 | return (4.8f * monIn); |
switches | 4:1c6819a42db0 | 45 | } |
switches | 0:60a522ae2e35 | 46 | |
switches | 0:60a522ae2e35 | 47 | // main() runs in its own thread in the OS |
switches | 0:60a522ae2e35 | 48 | // (note the calls to Thread::wait below for delays) |
switches | 0:60a522ae2e35 | 49 | int main() |
switches | 0:60a522ae2e35 | 50 | { |
switches | 4:1c6819a42db0 | 51 | float aIn; |
switches | 7:62efbc5411c8 | 52 | char dataBuf[2]; |
switches | 7:62efbc5411c8 | 53 | int ledCnt = 0; |
switches | 7:62efbc5411c8 | 54 | |
switches | 4:1c6819a42db0 | 55 | daplink.printf("Initializing MAX32630FTHR\r\n"); |
switches | 6:fa0134a8ac32 | 56 | // pegasus.init(MAX32630FTHR::VIO_3V3); |
switches | 4:1c6819a42db0 | 57 | daplink.printf("Checking Supplies\r\n"); |
switches | 4:1c6819a42db0 | 58 | aIn = 2.4f * vdd12In; |
switches | 4:1c6819a42db0 | 59 | daplink.printf("vdd12 = %f\r\n", aIn); |
switches | 7:62efbc5411c8 | 60 | if ((aIn < 1.0f) || (aIn > 1.4f)) { |
switches | 7:62efbc5411c8 | 61 | testFailed(); |
switches | 7:62efbc5411c8 | 62 | } |
switches | 4:1c6819a42db0 | 63 | aIn = 2.4f * vdd18In; |
switches | 4:1c6819a42db0 | 64 | daplink.printf("vdd18 = %f\r\n", aIn); |
switches | 7:62efbc5411c8 | 65 | if ((aIn < 1.6f) || (aIn > 2.0f)) { |
switches | 7:62efbc5411c8 | 66 | testFailed(); |
switches | 7:62efbc5411c8 | 67 | } |
switches | 4:1c6819a42db0 | 68 | aIn = 4.8f * vddbIn; |
switches | 4:1c6819a42db0 | 69 | daplink.printf("vddb = %f\r\n", aIn); |
switches | 7:62efbc5411c8 | 70 | if ((aIn < 3.0f) || (aIn > 3.6f)) { |
switches | 7:62efbc5411c8 | 71 | testFailed(); |
switches | 7:62efbc5411c8 | 72 | } |
switches | 4:1c6819a42db0 | 73 | aIn = 2.4f * vrtcIn; |
switches | 4:1c6819a42db0 | 74 | daplink.printf("vrtc = %f\r\n", aIn); |
switches | 7:62efbc5411c8 | 75 | if ((aIn < 1.6f) || (aIn > 2.0f)) { |
switches | 7:62efbc5411c8 | 76 | testFailed(); |
switches | 7:62efbc5411c8 | 77 | } |
switches | 4:1c6819a42db0 | 78 | aIn = readMon(MAX14690::MON_SYS); |
switches | 4:1c6819a42db0 | 79 | daplink.printf("sys = %f\r\n", aIn); |
switches | 7:62efbc5411c8 | 80 | if ((aIn < 3.0f) || (aIn > 5.0f)) { |
switches | 7:62efbc5411c8 | 81 | testFailed(); |
switches | 7:62efbc5411c8 | 82 | } |
switches | 4:1c6819a42db0 | 83 | aIn = readMon(MAX14690::MON_BUCK1); |
switches | 4:1c6819a42db0 | 84 | daplink.printf("buck1 = %f\r\n", aIn); |
switches | 7:62efbc5411c8 | 85 | if ((aIn < 1.0f) || (aIn > 1.4f)) { |
switches | 7:62efbc5411c8 | 86 | testFailed(); |
switches | 7:62efbc5411c8 | 87 | } |
switches | 4:1c6819a42db0 | 88 | aIn = readMon(MAX14690::MON_BUCK2); |
switches | 4:1c6819a42db0 | 89 | daplink.printf("buck2 = %f\r\n", aIn); |
switches | 7:62efbc5411c8 | 90 | if ((aIn < 1.6f) || (aIn > 2.0f)) { |
switches | 7:62efbc5411c8 | 91 | testFailed(); |
switches | 7:62efbc5411c8 | 92 | } |
switches | 4:1c6819a42db0 | 93 | aIn = readMon(MAX14690::MON_LDO1); |
switches | 4:1c6819a42db0 | 94 | daplink.printf("ldo1 = %f\r\n", aIn); |
switches | 7:62efbc5411c8 | 95 | if ((aIn < 1.6f) || (aIn > 2.0f)) { |
switches | 7:62efbc5411c8 | 96 | testFailed(); |
switches | 7:62efbc5411c8 | 97 | } |
switches | 4:1c6819a42db0 | 98 | aIn = readMon(MAX14690::MON_LDO2); |
switches | 4:1c6819a42db0 | 99 | daplink.printf("ldo2 = %f\r\n", aIn); |
switches | 7:62efbc5411c8 | 100 | if ((aIn < 3.0f) || (aIn > 3.6f)) { |
switches | 7:62efbc5411c8 | 101 | testFailed(); |
switches | 7:62efbc5411c8 | 102 | } |
switches | 4:1c6819a42db0 | 103 | aIn = readMon(MAX14690::MON_LDO3); |
switches | 4:1c6819a42db0 | 104 | daplink.printf("ldo3 = %f\r\n", aIn); |
switches | 4:1c6819a42db0 | 105 | aIn = readMon(MAX14690::MON_LDO3); |
switches | 1:464c8b3634dc | 106 | |
switches | 7:62efbc5411c8 | 107 | bLED = LED_ON; |
switches | 1:464c8b3634dc | 108 | |
switches | 7:62efbc5411c8 | 109 | daplink.printf("Checking micro SD Card\r\n"); |
switches | 7:62efbc5411c8 | 110 | FILE *fp = fopen("/sd/myfile.txt", "r"); |
switches | 7:62efbc5411c8 | 111 | if(fp == NULL) { |
switches | 7:62efbc5411c8 | 112 | daplink.printf("Unable to open 'myfile.txt'\r\n"); |
switches | 7:62efbc5411c8 | 113 | testFailed(); |
switches | 7:62efbc5411c8 | 114 | } |
switches | 7:62efbc5411c8 | 115 | daplink.printf("micro SD Card present\r\n"); |
switches | 1:464c8b3634dc | 116 | rLED = LED_OFF; |
switches | 0:60a522ae2e35 | 117 | |
switches | 7:62efbc5411c8 | 118 | daplink.printf("Checking BMI160\r\n"); |
switches | 7:62efbc5411c8 | 119 | dataBuf[0] = 0x00; |
switches | 7:62efbc5411c8 | 120 | if (pegasus.i2c.write(BMI160_I2C_ADDR, dataBuf, 1, 1) != 0) testFailed(); |
switches | 7:62efbc5411c8 | 121 | if (pegasus.i2c.read(BMI160_I2C_ADDR, dataBuf, 1) != 0) testFailed(); |
switches | 7:62efbc5411c8 | 122 | if (dataBuf[0] != 0xD1) testFailed(); |
switches | 7:62efbc5411c8 | 123 | daplink.printf("BMI160 present\r\n"); |
switches | 7:62efbc5411c8 | 124 | gLED = LED_ON; |
switches | 7:62efbc5411c8 | 125 | |
switches | 7:62efbc5411c8 | 126 | |
switches | 7:62efbc5411c8 | 127 | |
switches | 4:1c6819a42db0 | 128 | daplink.printf("Self Test Passed\r\n"); |
switches | 7:62efbc5411c8 | 129 | rLED = LED_ON; |
switches | 7:62efbc5411c8 | 130 | gLED = LED_ON; |
switches | 7:62efbc5411c8 | 131 | bLED = LED_ON; |
switches | 7:62efbc5411c8 | 132 | |
switches | 0:60a522ae2e35 | 133 | while (true) { |
switches | 7:62efbc5411c8 | 134 | if (!button) { |
switches | 7:62efbc5411c8 | 135 | keyboard.mediaControl(KEY_MUTE); |
switches | 7:62efbc5411c8 | 136 | ledCnt++; |
switches | 7:62efbc5411c8 | 137 | rLED = (ledCnt & 1); |
switches | 7:62efbc5411c8 | 138 | gLED = (ledCnt & 2); |
switches | 7:62efbc5411c8 | 139 | bLED = (ledCnt & 4); |
switches | 7:62efbc5411c8 | 140 | Thread::wait(500); |
switches | 7:62efbc5411c8 | 141 | } else { |
switches | 7:62efbc5411c8 | 142 | Thread::wait(50); |
switches | 7:62efbc5411c8 | 143 | } |
switches | 0:60a522ae2e35 | 144 | } |
switches | 0:60a522ae2e35 | 145 | } |
switches | 0:60a522ae2e35 | 146 |