Test program running on MAX32625MBED. Control through USB Serial commands using a terminal emulator such as teraterm or putty.
Dependencies: MaximTinyTester MAX11131 CmdLine MAX541 USBDevice
Diff: main.cpp
- Revision:
- 17:c2f46173f6b2
- Parent:
- 16:09f10869b638
- Child:
- 18:6d02d823fd7a
--- a/main.cpp Sun Jul 14 06:27:24 2019 +0000 +++ b/main.cpp Thu Jul 18 10:54:51 2019 +0000 @@ -47,6 +47,8 @@ // - add http://developer.mbed.org/teams/MaximIntegrated/code/max32630fthr/ #include "mbed.h" +// mbed shared event queue run onTimerTick() in Thread context not Interrupt context +#include "mbed_events.h" #if defined(TARGET) // TARGET_NAME macros from targets/TARGET_Maxim/TARGET_MAX32625/device/mxc_device.h // Create a string definition for the TARGET @@ -303,6 +305,22 @@ const float ADC_FULL_SCALE_VOLTAGE = 1.500; // //-------------------------------------------------- +#elif defined(TARGET_MAX32620FTHR) +#warning "TARGET_MAX32620FTHR not previously tested; need to define pins..." +//#define USE_LEDS 0 ? +#define analogIn4_IS_HIGH_RANGE_OF_analogIn0 1 +#warning "TARGET_MAX32620FTHR not previously tested; need to verify ADC_FULL_SCALE_VOLTAGE..." +const float ADC_FULL_SCALE_VOLTAGE = 1.200; +// +//-------------------------------------------------- +#elif defined(TARGET_MAX32625PICO) +#warning "TARGET_MAX32625PICO not previously tested; need to define pins..." +//#define USE_LEDS 0 ? +#define analogIn4_IS_HIGH_RANGE_OF_analogIn0 1 +#warning "TARGET_MAX32620FTHR not previously tested; need to verify ADC_FULL_SCALE_VOLTAGE..." +const float ADC_FULL_SCALE_VOLTAGE = 1.200; +// +//-------------------------------------------------- #elif defined(TARGET_NUCLEO_F446RE) || defined(TARGET_NUCLEO_F401RE) // TODO1: target NUCLEO_F446RE // @@ -577,6 +595,32 @@ DigitalOut spi2_max541_cs(SPI2_SS); // TARGET_MAX32635MBED: P2_7 Arduino 2x3-pin header #define HAS_SPI2_MAX541 1 // +#elif defined(TARGET_MAX32620FTHR) +#warning "TARGET_MAX32620FTHR not previously tested; need to define SPI pins..." +// Note to software maintainer: +// when adding new platform support, +// add another #elif block above to support the new platform +// +// SPI0 P0_ PMOD Port 0 Back access +//SPI spi0(SPI0_MOSI, SPI0_MISO, SPI0_SCK); // mosi, miso, sclk spi1 TARGET_MAX32620FTHR: PMOD Port 0 Back access +//DigitalOut spi_cs0(SPI0_SS); // TARGET_MAX32620FTHR: PMOD Port 0 Back access +// +// SPI1 P1_ PMOD Port 1 Top Access +SPI spi(SPI1_MOSI, SPI1_MISO, SPI1_SCK); // mosi, miso, sclk spi1 TARGET_MAX32620FTHR: PMOD Port 1 Top Access +DigitalOut spi_cs(SPI1_SS); // TARGET_MAX32620FTHR: PMOD Port 1 Top Access +// +// SPI2 P5_ Feather J1.11,12,13 +//SPI spi2(SPI2_MOSI, SPI2_MISO, SPI2_SCK); // mosi, miso, sclk spi1 TARGET_MAX32620FTHR: Feather J1.11,12,13 +//DigitalOut spi_cs2(SPI2_SS); // TARGET_MAX32620FTHR: Feather J1.11,12,13 +// +#elif defined(TARGET_MAX32625PICO) +#warning "TARGET_MAX32625PICO not previously tested; need to define SPI pins..." +// Note to software maintainer: +// when adding new platform support, +// add another #elif block above to support the new platform +SPI spi(SPI_MOSI, SPI_MISO, SPI_SCK); // mosi, miso, sclk spi1 TARGET_MAX32625PICO: 15 P0_5 MOSI; 14 P0_6 MISO; 16 P0_4 SCLK +DigitalOut spi_cs(SPI_SS); // TARGET_MAX32625PICO: 13 P0_7 SSEL +// #elif defined(TARGET_MAX32600) SPI spi(SPI2_MOSI, SPI2_MISO, SPI2_SCK); // mosi, miso, sclk spi1 TARGET_MAX32600MBED: Arduino 10-pin header D11 D12 D13 DigitalOut spi_cs(SPI2_SS); // Generic: Arduino 10-pin header D10 @@ -598,8 +642,15 @@ SPI spi(SPI2_MOSI, SPI2_MISO, SPI2_SCK); // mosi, miso, sclk spi2 MAX32630FTHR: P5_1, P5_2, P5_0 // DigitalOut spi_cs(P3_0); +// #else // unknown target +#warning "target not previously tested; need to define SPI pins..." +// Note to software maintainer: +// when adding new platform support, +// add another #elif block above to support the new platform +//SPI spi(SPI_MOSI, SPI_MISO, SPI_SCK); // mosi, miso, sclk spi1 TARGET_xxx: Arduino 10-pin header D11 D12 D13 +//DigitalOut spi_cs(SPI_CS); // TARGET_xxx: PX_x Arduino 10-pin header D10 #endif #endif @@ -717,6 +768,7 @@ #elif defined(TARGET_LPC1768) #else // unknown target +#warning "target not previously tested; need to define I2C pins..." #endif // #endif @@ -771,6 +823,25 @@ // Virtual serial port over USB // The baud rate does not affect the virtual USBSerial UART. USBSerial serial; +// +//-------------------------------------------------- +#elif defined(TARGET_MAX32620FTHR) +#warning "TARGET_MAX32620FTHR not previously tested; need to define serial pins..." +// Note to software maintainer: +// when adding new platform support, +// add another #elif block above to support the new platform +//Serial serial(SERIAL_TX, SERIAL_RX); // tx, rx +Serial serial(USBTX, USBRX); // tx, rx +//Serial serial(UART_TX, UART_RX); // tx, rx +// +//-------------------------------------------------- +#elif defined(TARGET_MAX32625PICO) +#warning "TARGET_MAX32625PICO not previously tested; need to verify serial pins..." +// Note to software maintainer: +// when adding new platform support, +// add another #elif block above to support the new platform +Serial serial(UART_TX, UART_RX); // tx, rx +// //-------------------------------------------------- #elif defined(TARGET_MAX32600) #include "USBSerial.h" @@ -790,6 +861,18 @@ Serial serial(USBTX, USBRX); // tx, rx #else // unknown target +#if defined(SERIAL_TX) +#warning "target not previously tested; guess serial pins are SERIAL_TX, SERIAL_RX..." +Serial serial(SERIAL_TX, SERIAL_RX); // tx, rx +#elif defined(USBTX) +#warning "target not previously tested; guess serial pins are USBTX, USBRX..." +Serial serial(USBTX, USBRX); // tx, rx +#elif defined(UART_TX) +#warning "target not previously tested; guess serial pins are UART_TX, UART_RX..." +Serial serial(UART_TX, UART_RX); // tx, rx +#else +#warning "target not previously tested; need to define serial pins..." +#endif #endif void on_immediate_0x21(); // Unicode (U+0021) ! EXCLAMATION MARK @@ -1378,6 +1461,100 @@ AnalogIn analogIn5(AIN_5); // TARGET_MAX32630 J1.6 AIN_5 = AIN1 / 5.0 fullscale is 6.0V #endif //-------------------------------------------------- +#elif defined(TARGET_MAX32620FTHR) +#warning "TARGET_MAX32620FTHR not previously tested; need to verify analogIn0..." + #define HAS_analogIn0 1 + #define HAS_analogIn1 1 + #define HAS_analogIn2 1 + #define HAS_analogIn3 1 + #define HAS_analogIn4 1 + #define HAS_analogIn5 1 + #define HAS_analogIn6 1 + #define HAS_analogIn7 1 + #define HAS_analogIn8 1 + #define HAS_analogIn9 1 +// #define HAS_analogIn10 0 +// #define HAS_analogIn11 0 +// #define HAS_analogIn12 0 +// #define HAS_analogIn13 0 +// #define HAS_analogIn14 0 +// #define HAS_analogIn15 0 +#if HAS_analogIn0 + AnalogIn analogIn0(AIN_0); // TARGET_MAX32620FTHR J1.5 AIN_0 = AIN0 pin fullscale is 1.2V +#endif +#if HAS_analogIn1 + AnalogIn analogIn1(AIN_1); // TARGET_MAX32620FTHR J1.6 AIN_1 = AIN1 pin fullscale is 1.2V +#endif +#if HAS_analogIn2 + AnalogIn analogIn2(AIN_2); // TARGET_MAX32620FTHR J1.7 AIN_2 = AIN2 pin fullscale is 1.2V +#endif +#if HAS_analogIn3 + AnalogIn analogIn3(AIN_3); // TARGET_MAX32620FTHR J1.8 AIN_3 = AIN3 pin fullscale is 1.2V +#endif +#if HAS_analogIn4 + AnalogIn analogIn4(AIN_4); // TARGET_MAX32620FTHR J1.5 AIN_4 = AIN0 / 5.0 fullscale is 6.0V +#endif +#if HAS_analogIn5 + AnalogIn analogIn5(AIN_5); // TARGET_MAX32620FTHR J1.6 AIN_5 = AIN1 / 5.0 fullscale is 6.0V +#endif +#if HAS_analogIn6 + AnalogIn analogIn6(AIN_6); // TARGET_MAX32620FTHR AIN_6 = VDDB / 4.0 fullscale is 4.8V +#endif +#if HAS_analogIn7 + AnalogIn analogIn7(AIN_7); // TARGET_MAX32620FTHR AIN_7 = VDD18 fullscale is 1.2V +#endif +#if HAS_analogIn8 + AnalogIn analogIn8(AIN_8); // TARGET_MAX32620FTHR AIN_8 = VDD12 fullscale is 1.2V +#endif +#if HAS_analogIn9 + AnalogIn analogIn9(AIN_9); // TARGET_MAX32620FTHR AIN_9 = VRTC / 2.0 fullscale is 2.4V +#endif +#if HAS_analogIn10 + AnalogIn analogIn10(____); // TARGET_MAX32620FTHR AIN_10 = x undefined? +#endif +#if HAS_analogIn11 + AnalogIn analogIn11(____); // TARGET_MAX32620FTHR AIN_11 = VDDIO / 4.0 fullscale is 4.8V +#endif +#if HAS_analogIn12 + AnalogIn analogIn12(____); // TARGET_MAX32620FTHR AIN_12 = VDDIOH / 4.0 fullscale is 4.8V +#endif +#if HAS_analogIn13 + AnalogIn analogIn13(____); +#endif +#if HAS_analogIn14 + AnalogIn analogIn14(____); +#endif +#if HAS_analogIn15 + AnalogIn analogIn15(____); +#endif +//-------------------------------------------------- +#elif defined(TARGET_MAX32625PICO) +#warning "TARGET_MAX32625PICO not previously tested; need to verify analogIn0..." + #define HAS_analogIn0 1 + #define HAS_analogIn1 1 + #define HAS_analogIn2 1 + #define HAS_analogIn3 1 + #define HAS_analogIn4 1 + #define HAS_analogIn5 1 +#if HAS_analogIn0 + AnalogIn analogIn0(AIN_0); // TARGET_MAX32630 J1.5 AIN_0 = AIN0 pin fullscale is 1.2V +#endif +#if HAS_analogIn1 + AnalogIn analogIn1(AIN_1); // TARGET_MAX32630 J1.6 AIN_1 = AIN1 pin fullscale is 1.2V +#endif +#if HAS_analogIn2 + AnalogIn analogIn2(AIN_2); // TARGET_MAX32630 J1.7 AIN_2 = AIN2 pin fullscale is 1.2V +#endif +#if HAS_analogIn3 + AnalogIn analogIn3(AIN_3); // TARGET_MAX32630 J1.8 AIN_3 = AIN3 pin fullscale is 1.2V +#endif +#if HAS_analogIn4 + AnalogIn analogIn4(AIN_4); // TARGET_MAX32630 J1.5 AIN_4 = AIN0 / 5.0 fullscale is 6.0V +#endif +#if HAS_analogIn5 + AnalogIn analogIn5(AIN_5); // TARGET_MAX32630 J1.6 AIN_5 = AIN1 / 5.0 fullscale is 6.0V +#endif +//-------------------------------------------------- #elif defined(TARGET_MAX32600) #define HAS_analogIn0 1 #define HAS_analogIn1 1 @@ -1641,15 +1818,28 @@ #define HAS_BUTTON1_DEMO_INTERRUPT 1 #define HAS_BUTTON2_DEMO 0 #define HAS_BUTTON2_DEMO_INTERRUPT 0 +#elif defined(TARGET_MAX32625PICO) +#warning "TARGET_MAX32625PICO not previously tested; need to define buttons..." +#define HAS_BUTTON1_DEMO_INTERRUPT 1 +#define HAS_BUTTON2_DEMO 0 +#define HAS_BUTTON2_DEMO_INTERRUPT 0 #elif defined(TARGET_MAX32625) #define HAS_BUTTON1_DEMO_INTERRUPT 1 #define HAS_BUTTON2_DEMO_INTERRUPT 1 +#elif defined(TARGET_MAX32620FTHR) +#warning "TARGET_MAX32620FTHR not previously tested; need to define buttons..." +#define BUTTON1 SW1 +#define HAS_BUTTON1_DEMO_INTERRUPT 1 +#define HAS_BUTTON2_DEMO 0 +#define HAS_BUTTON2_DEMO_INTERRUPT 0 #elif defined(TARGET_NUCLEO_F446RE) #define HAS_BUTTON1_DEMO_INTERRUPT 0 #define HAS_BUTTON2_DEMO_INTERRUPT 0 #elif defined(TARGET_NUCLEO_F401RE) #define HAS_BUTTON1_DEMO_INTERRUPT 0 #define HAS_BUTTON2_DEMO_INTERRUPT 0 +#else +#warning "target not previously tested; need to define buttons..." #endif // #ifndef HAS_BUTTON1_DEMO @@ -1697,7 +1887,9 @@ //-------------------------------------------------- // Ticker is the periodic interrupt timer itself +#ifndef USE_PERIODIC_TIMER #define USE_PERIODIC_TIMER 0 +#endif #if USE_PERIODIC_TIMER Ticker periodicInterruptTimer; us_timestamp_t periodicInterruptTimer_interval_usec = 50; @@ -2424,6 +2616,24 @@ ADC_FULL_SCALE_VOLTAGE, // analogIn13 ADC_FULL_SCALE_VOLTAGE, // analogIn14 ADC_FULL_SCALE_VOLTAGE // analogIn15 +# elif defined(TARGET_MAX32620FTHR) +#warning "TARGET_MAX32620FTHR not previously tested; need to verify analogIn0..." + ADC_FULL_SCALE_VOLTAGE, // analogIn0 + ADC_FULL_SCALE_VOLTAGE, // analogIn1 + ADC_FULL_SCALE_VOLTAGE, // analogIn2 + ADC_FULL_SCALE_VOLTAGE, // analogIn3 + ADC_FULL_SCALE_VOLTAGE * 5.0f, // analogIn4 // AIN_4 = AIN0 / 5.0 fullscale is 6.0V + ADC_FULL_SCALE_VOLTAGE * 5.0f, // analogIn4 // AIN_5 = AIN1 / 5.0 fullscale is 6.0V + ADC_FULL_SCALE_VOLTAGE * 4.0f, // analogIn6 // AIN_6 = VDDB / 4.0 fullscale is 4.8V + ADC_FULL_SCALE_VOLTAGE, // analogIn7 // AIN_7 = VDD18 fullscale is 1.2V + ADC_FULL_SCALE_VOLTAGE, // analogIn8 // AIN_8 = VDD12 fullscale is 1.2V + ADC_FULL_SCALE_VOLTAGE * 2.0f, // analogIn9 // AIN_9 = VRTC / 2.0 fullscale is 2.4V + ADC_FULL_SCALE_VOLTAGE, // analogIn10 // AIN_10 = x undefined? + ADC_FULL_SCALE_VOLTAGE * 4.0f, // analogIn11 // AIN_11 = VDDIO / 4.0 fullscale is 4.8V + ADC_FULL_SCALE_VOLTAGE * 4.0f, // analogIn12 // AIN_12 = VDDIOH / 4.0 fullscale is 4.8V + ADC_FULL_SCALE_VOLTAGE, // analogIn13 + ADC_FULL_SCALE_VOLTAGE, // analogIn14 + ADC_FULL_SCALE_VOLTAGE // analogIn15 #elif defined(TARGET_MAX32625MBED) ADC_FULL_SCALE_VOLTAGE * 1.0f, // analogIn0 // fullscale is 1.2V ADC_FULL_SCALE_VOLTAGE * 1.0f, // analogIn1 // fullscale is 1.2V @@ -2617,10 +2827,21 @@ //us_timestamp_t interval_usec = 100000; // 100ms periodicInterruptTimer_interval_usec = 100000; // 100ms # if HAS_DAPLINK_SERIAL - DAPLINKserial.printf(" Timer Enable %d us\r\n", periodicInterruptTimer_interval_usec); + DAPLINKserial.printf(" TE rate=%lluus -- Timer Enable\r\n", periodicInterruptTimer_interval_usec); # endif - serial.printf(" Timer Enable %d us", periodicInterruptTimer_interval_usec); + serial.printf(" TE rate=%lluus -- Timer Enable", periodicInterruptTimer_interval_usec); +#if 1 + // mbed shared event queue run onTimerTick() in Thread context not Interrupt context + periodicInterruptTimer.attach_us(mbed_event_queue()->event(onTimerTick), + periodicInterruptTimer_interval_usec); + // Works if rate=620Hz or less, Fails if rate=750Hz + // MbedOS Error Info Error Status 0x80FF0144 code 324 module 255 + // Assertion failed; id location 0xBE6F mbed-os.lib/events/Event.h+158 + // Current thread main id 0x200036f8 entry 0xc22f stacksize 0x1000 stackmem 0x200026f8 sp 0x2007ff60 + // Seems not robust about overrun / sample rate too fast +#else periodicInterruptTimer.attach_us(&onTimerTick, periodicInterruptTimer_interval_usec); +#endif // -- periodicInterruptTimer.attach(&onTimerTick, interval_sec); // the address of the function to be attached (onTimerTick) and the interval (2 seconds) // -- periodicInterruptTimer.attach_us(&onTimerTick, interval_usec); // the address of the function to be attached (onTimerTick) and the interval (2 seconds) // -- periodicInterruptTimer.attach(Callback<void()> func, float t); @@ -6351,6 +6572,28 @@ # endif #endif // HAS_BUTTON2_DEMO_INTERRUPT +#if defined(TARGET_MAX32630) + // Timer tick needs to be the highest priority (priority 0, the default). + // DAPLINKserial interferes with the timer tick interrupt. + // Lower the priority of the serial port interrupts to avoid disrupting onTimerTick() handler. + NVIC_SetPriority(UART0_IRQn, 2); // reservedBlueToothSerial(P0_1, P0_0) // 0=highest priority; 1=lower + NVIC_SetPriority(UART1_IRQn, 2); // DAPLINKserial(P2_1, P2_0) // 0=highest priority; 1=lower + NVIC_SetPriority(UART2_IRQn, 2); // reservedSerial(P3_1, P3_0) // 0=highest priority; 1=lower + NVIC_SetPriority(UART3_IRQn, 2); // reservedSerial(P5_4, P5_3) // 0=highest priority; 1=lower + NVIC_SetPriority(GPIO_P0_IRQn, 2); // 0=highest priority; 1=lower + NVIC_SetPriority(GPIO_P1_IRQn, 2); // 0=highest priority; 1=lower + NVIC_SetPriority(GPIO_P2_IRQn, 2); // 0=highest priority; 1=lower + NVIC_SetPriority(GPIO_P3_IRQn, 2); // 0=highest priority; 1=lower + NVIC_SetPriority(GPIO_P4_IRQn, 2); // 0=highest priority; 1=lower + NVIC_SetPriority(GPIO_P5_IRQn, 2); // 0=highest priority; 1=lower + NVIC_SetPriority(GPIO_P6_IRQn, 2); // 0=highest priority; 1=lower + NVIC_SetPriority(GPIO_P7_IRQn, 2); // 0=highest priority; 1=lower + NVIC_SetPriority(GPIO_P8_IRQn, 2); // 0=highest priority; 1=lower + //~ NVIC_SetPriority(RTC0_IRQn, 0); // 0=highest priority; 1=lower + //~ NVIC_SetPriority(RTC3_IRQn, 0); // 0=highest priority; 1=lower + //~ NVIC_SetPriority(US_TIMER_IRQn, 0); // 0=highest priority; 1=lower +#endif + #if HAS_SPI // spi init // mode | POL PHA