From e5f4dba28e36ed1a95804d05a9710230a2413f47 Mon Sep 17 00:00:00 2001 From: kurte Date: Sat, 8 Feb 2025 14:38:24 -0800 Subject: [PATCH 1/6] Portenta H7: Add spis to overlay plus fix GPIOS This is a partial fix for: #68 the spis line was not in the zephyr,user { section of the ovleray file. I added it with one entry: spis = <&spi2>; Updated: the GPIO table, that only the LEDS should be defined with GPIO_ACTIVE_LOW. --- loader/boards/arduino_portenta_h7_m7.conf | 2 + loader/boards/arduino_portenta_h7_m7.overlay | 42 ++++++++++++-------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/loader/boards/arduino_portenta_h7_m7.conf b/loader/boards/arduino_portenta_h7_m7.conf index acee48b1..1f624ad2 100644 --- a/loader/boards/arduino_portenta_h7_m7.conf +++ b/loader/boards/arduino_portenta_h7_m7.conf @@ -26,6 +26,8 @@ CONFIG_LLEXT_HEAP_SIZE=128 #CONFIG_ADC=y #CONFIG_PWM=y +CONFIG_SPI_ASYNC=y +CONFIG_SPI_STM32_INTERRUPT=y CONFIG_NET_CORE_LOG_LEVEL_DBG=y diff --git a/loader/boards/arduino_portenta_h7_m7.overlay b/loader/boards/arduino_portenta_h7_m7.overlay index d5f0aea8..c013ee43 100644 --- a/loader/boards/arduino_portenta_h7_m7.overlay +++ b/loader/boards/arduino_portenta_h7_m7.overlay @@ -25,6 +25,13 @@ status = "okay"; }; +&spi2 { + status = "okay"; + pinctrl-0 = <&spi2_sck_pi1 + &spi2_miso_pc2 &spi2_mosi_pc3>; + pinctrl-names = "default"; +}; + &rng { status = "okay"; }; @@ -66,22 +73,24 @@ / { zephyr,user { - digital-pin-gpios = <&gpioh 15 GPIO_ACTIVE_LOW>, - <&gpiok 1 GPIO_ACTIVE_LOW>, - <&gpioj 11 GPIO_ACTIVE_LOW>, - <&gpiog 7 GPIO_ACTIVE_LOW>, - <&gpioc 7 GPIO_ACTIVE_LOW>, - <&gpioc 6 GPIO_ACTIVE_LOW>, - <&gpioa 8 GPIO_ACTIVE_LOW>, - <&gpioi 0 GPIO_ACTIVE_LOW>, - <&gpioc 3 GPIO_ACTIVE_LOW>, - <&gpioi 1 GPIO_ACTIVE_LOW>, - <&gpioc 2 GPIO_ACTIVE_LOW>, - <&gpioh 8 GPIO_ACTIVE_LOW>, - <&gpioh 7 GPIO_ACTIVE_LOW>, - <&gpioa 10 GPIO_ACTIVE_LOW>, - <&gpioa 9 GPIO_ACTIVE_LOW>, - <&gpiok 5 GPIO_ACTIVE_LOW>; // LEDR + digital-pin-gpios = <&gpioh 15 0>, + <&gpiok 1 0>, + <&gpioj 11 0>, + <&gpiog 7 0>, + <&gpioc 7 0>, + <&gpioc 6 0>, + <&gpioa 8 0>, + <&gpioi 0 0>, + <&gpioc 3 0>, + <&gpioi 1 0>, + <&gpioc 2 0>, + <&gpioh 8 0>, + <&gpioh 7 0>, + <&gpioa 10 0>, + <&gpioa 9 0>, + <&gpiok 5 GPIO_ACTIVE_LOW>, // LEDR + <&gpiok 6 GPIO_ACTIVE_LOW>, + <&gpiok 7 GPIO_ACTIVE_LOW>; builtin-led-gpios = <&gpiok 5 GPIO_ACTIVE_LOW>, <&gpiok 6 GPIO_ACTIVE_LOW>, @@ -90,5 +99,6 @@ serials = <&cdc_acm_uart0>,<&usart6>, <&usart1>, <&uart4>; cdc-acm = <&cdc_acm_uart0>; i2cs = <&i2c4>; + spis = <&spi2>; }; }; From 56b9506e88c6c518fce096c30dab52a25212fdd0 Mon Sep 17 00:00:00 2001 From: kurte Date: Sat, 8 Feb 2025 15:52:17 -0800 Subject: [PATCH 2/6] Update arduino_portenta_h7_m7.overlay Added in the other two Wire objects to match the MBED version. i2cs = <&i2c3>, <&i2c1>, <&i2c4>; I checked it out with simple wire scanner sketch that checks Wire, Wire1 and Wire2. And then tried adding QWIIC Button first to the I2C0 section of breakout board and it was found on Wire. Moved it to I2C1 section and found with Wire1 and then moved to I2C2 section and found on Wire2 --- loader/boards/arduino_portenta_h7_m7.overlay | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/loader/boards/arduino_portenta_h7_m7.overlay b/loader/boards/arduino_portenta_h7_m7.overlay index c013ee43..125f2bed 100644 --- a/loader/boards/arduino_portenta_h7_m7.overlay +++ b/loader/boards/arduino_portenta_h7_m7.overlay @@ -21,6 +21,14 @@ status = "okay"; }; +&i2c3 { + status = "okay"; +}; + +&i2c1 { + status = "okay"; +}; + &i2c4 { status = "okay"; }; @@ -98,7 +106,7 @@ serials = <&cdc_acm_uart0>,<&usart6>, <&usart1>, <&uart4>; cdc-acm = <&cdc_acm_uart0>; - i2cs = <&i2c4>; + i2cs = <&i2c3>, <&i2c1>, <&i2c4>; spis = <&spi2>; }; }; From c0de1e36c2bb433998f666dac5c10d4e3c44c94a Mon Sep 17 00:00:00 2001 From: kurte Date: Mon, 10 Feb 2025 05:37:32 -0800 Subject: [PATCH 3/6] Portenta H7: update digital-pin-gpios to be same as MBED version --- loader/boards/arduino_portenta_h7_m7.overlay | 202 ++++++++++++++++++- 1 file changed, 197 insertions(+), 5 deletions(-) diff --git a/loader/boards/arduino_portenta_h7_m7.overlay b/loader/boards/arduino_portenta_h7_m7.overlay index 125f2bed..f4204f76 100644 --- a/loader/boards/arduino_portenta_h7_m7.overlay +++ b/loader/boards/arduino_portenta_h7_m7.overlay @@ -50,6 +50,16 @@ zephyr,shell-uart = &usart6; zephyr,cdc-acm-uart0 = &usart6; }; + + /* used to overcome problems with _C analog pins */ + gpioz: gpio@deadbeef { + compatible = "vnd,gpio"; + gpio-controller; + reg = <0xdeadbeef 0x1000>; + #gpio-cells = <0x2>; + status = "okay"; + }; + }; / { @@ -81,7 +91,7 @@ / { zephyr,user { - digital-pin-gpios = <&gpioh 15 0>, + digital-pin-gpios = <&gpioh 15 0>, /* D0 */ <&gpiok 1 0>, <&gpioj 11 0>, <&gpiog 7 0>, @@ -95,10 +105,192 @@ <&gpioh 8 0>, <&gpioh 7 0>, <&gpioa 10 0>, - <&gpioa 9 0>, - <&gpiok 5 GPIO_ACTIVE_LOW>, // LEDR - <&gpiok 6 GPIO_ACTIVE_LOW>, - <&gpiok 7 GPIO_ACTIVE_LOW>; + <&gpioa 9 0>, /* D14 */ + + <&gpioz 0 0>, /* A0 ADC2_INP0 */ + <&gpioz 1 0>, /* A1 ADC2_INP1 */ + <&gpioz 2 0>, /* A2 ADC3_INP0 */ + <&gpioz 3 0>, /* A3 ADC3_INP1 */ + <&gpioc 2 0>, /* A4 _ALT0? ADC1_INP12 */ + <&gpioc 3 0>, /* A5 _ALT0? ADC1_INP13 */ + <&gpioa 4 0>, /* A6 ADC1_INP18 */ + <&gpioa 6 0>, /* A7 ADC1_INP7 */ + + + <&gpiok 5 GPIO_ACTIVE_LOW>, // LEDR + <&gpiok 6 GPIO_ACTIVE_LOW>, // LEDG + <&gpiok 7 GPIO_ACTIVE_LOW>, // LEDB + + <&gpioa 0 0>, + <&gpioa 1 0>, + <&gpioa 2 0>, + <&gpioa 3 0>, + <&gpioa 4 0>, + <&gpioa 5 0>, + <&gpioa 6 0>, + <&gpioa 7 0>, + <&gpioa 8 0>, + <&gpioa 9 0>, + <&gpioa 10 0>, + <&gpioa 11 0>, + <&gpioa 12 0>, + <&gpioa 13 0>, + <&gpioa 14 0>, + <&gpioa 15 0>, + <&gpiob 0 0>, + <&gpiob 1 0>, + <&gpiob 2 0>, + <&gpiob 3 0>, + <&gpiob 4 0>, + <&gpiob 5 0>, + <&gpiob 6 0>, + <&gpiob 7 0>, + <&gpiob 8 0>, + <&gpiob 9 0>, + <&gpiob 10 0>, + <&gpiob 11 0>, + <&gpiob 12 0>, + <&gpiob 13 0>, + <&gpiob 14 0>, + <&gpiob 15 0>, + <&gpioc 0 0>, + <&gpioc 1 0>, + <&gpioc 2 0>, + <&gpioc 3 0>, + <&gpioc 4 0>, + <&gpioc 5 0>, + <&gpioc 6 0>, + <&gpioc 7 0>, + <&gpioc 8 0>, + <&gpioc 9 0>, + <&gpioc 10 0>, + <&gpioc 11 0>, + <&gpioc 12 0>, + <&gpioc 13 0>, + <&gpioc 14 0>, + <&gpioc 15 0>, + <&gpiod 0 0>, + <&gpiod 1 0>, + <&gpiod 2 0>, + <&gpiod 3 0>, + <&gpiod 4 0>, + <&gpiod 5 0>, + <&gpiod 6 0>, + <&gpiod 7 0>, + <&gpiod 8 0>, + <&gpiod 9 0>, + <&gpiod 10 0>, + <&gpiod 11 0>, + <&gpiod 12 0>, + <&gpiod 13 0>, + <&gpiod 14 0>, + <&gpiod 15 0>, + <&gpioe 0 0>, + <&gpioe 1 0>, + <&gpioe 2 0>, + <&gpioe 3 0>, + <&gpioe 4 0>, + <&gpioe 5 0>, + <&gpioe 6 0>, + <&gpioe 7 0>, + <&gpioe 8 0>, + <&gpioe 9 0>, + <&gpioe 10 0>, + <&gpioe 11 0>, + <&gpioe 12 0>, + <&gpioe 13 0>, + <&gpioe 14 0>, + <&gpioe 15 0>, + <&gpiof 0 0>, + <&gpiof 1 0>, + <&gpiof 2 0>, + <&gpiof 3 0>, + <&gpiof 4 0>, + <&gpiof 5 0>, + <&gpiof 6 0>, + <&gpiof 7 0>, + <&gpiof 8 0>, + <&gpiof 9 0>, + <&gpiof 10 0>, + <&gpiof 11 0>, + <&gpiof 12 0>, + <&gpiof 13 0>, + <&gpiof 14 0>, + <&gpiof 15 0>, + <&gpiog 0 0>, + <&gpiog 1 0>, + <&gpiog 2 0>, + <&gpiog 3 0>, + <&gpiog 4 0>, + <&gpiog 5 0>, + <&gpiog 6 0>, + <&gpiog 7 0>, + <&gpiog 8 0>, + <&gpiog 9 0>, + <&gpiog 10 0>, + <&gpiog 11 0>, + <&gpiog 12 0>, + <&gpiog 13 0>, + <&gpiog 14 0>, + <&gpiog 15 0>, + <&gpioh 0 0>, + <&gpioh 1 0>, + <&gpioh 2 0>, + <&gpioh 3 0>, + <&gpioh 4 0>, + <&gpioh 5 0>, + <&gpioh 6 0>, + <&gpioh 7 0>, + <&gpioh 8 0>, + <&gpioh 9 0>, + <&gpioh 10 0>, + <&gpioh 11 0>, + <&gpioh 12 0>, + <&gpioh 13 0>, + <&gpioh 14 0>, + <&gpioh 15 0>, + <&gpioi 0 0>, + <&gpioi 1 0>, + <&gpioi 2 0>, + <&gpioi 3 0>, + <&gpioi 4 0>, + <&gpioi 5 0>, + <&gpioi 6 0>, + <&gpioi 7 0>, + <&gpioi 8 0>, + <&gpioi 9 0>, + <&gpioi 10 0>, + <&gpioi 11 0>, + <&gpioi 12 0>, + <&gpioi 13 0>, + <&gpioi 14 0>, + <&gpioi 15 0>, + <&gpioj 0 0>, + <&gpioj 1 0>, + <&gpioj 2 0>, + <&gpioj 3 0>, + <&gpioj 4 0>, + <&gpioj 5 0>, + <&gpioj 6 0>, + <&gpioj 7 0>, + <&gpioj 8 0>, + <&gpioj 9 0>, + <&gpioj 10 0>, + <&gpioj 11 0>, + <&gpioj 12 0>, + <&gpioj 13 0>, + <&gpioj 14 0>, + <&gpioj 15 0>, + <&gpiok 0 0>, + <&gpiok 1 0>, + <&gpiok 2 0>, + <&gpiok 3 0>, + <&gpiok 4 0>, + <&gpiok 5 0>, + <&gpiok 6 0>, + <&gpiok 7 0>; + + builtin-led-gpios = <&gpiok 5 GPIO_ACTIVE_LOW>, <&gpiok 6 GPIO_ACTIVE_LOW>, From 7da8a97f929041dc1c7183a59218882bd7ed5e88 Mon Sep 17 00:00:00 2001 From: kurte Date: Wed, 12 Feb 2025 06:57:49 -0800 Subject: [PATCH 4/6] Update arduino_portenta_h7_m7.conf to enable memc resolves: #74 needed to add: CONFIG_MEMC=y to have the SDRAM enabled and as such not fault if you do anything with the SDRAM library. Also enabled CONFIG_DMA=y As not sure if that was needed but is in the GIGA .conf file Update arduino_portenta_h7_m7.overlay Add dma sections to remove the build warnings --- loader/boards/arduino_portenta_h7_m7.conf | 2 ++ loader/boards/arduino_portenta_h7_m7.overlay | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/loader/boards/arduino_portenta_h7_m7.conf b/loader/boards/arduino_portenta_h7_m7.conf index 1f624ad2..d148b1b1 100644 --- a/loader/boards/arduino_portenta_h7_m7.conf +++ b/loader/boards/arduino_portenta_h7_m7.conf @@ -26,6 +26,8 @@ CONFIG_LLEXT_HEAP_SIZE=128 #CONFIG_ADC=y #CONFIG_PWM=y +CONFIG_DMA=y +CONFIG_MEMC=y CONFIG_SPI_ASYNC=y CONFIG_SPI_STM32_INTERRUPT=y diff --git a/loader/boards/arduino_portenta_h7_m7.overlay b/loader/boards/arduino_portenta_h7_m7.overlay index f4204f76..a03190d0 100644 --- a/loader/boards/arduino_portenta_h7_m7.overlay +++ b/loader/boards/arduino_portenta_h7_m7.overlay @@ -40,6 +40,14 @@ pinctrl-names = "default"; }; +&dmamux1 { + status = "okay"; +}; + +&dma1 { + status = "okay"; +}; + &rng { status = "okay"; }; From c2f829ba9c6daaa460ac172e686573828182f214 Mon Sep 17 00:00:00 2001 From: kurte Date: Sat, 22 Feb 2025 10:51:44 -0800 Subject: [PATCH 5/6] Portenta H7M7 support for analogWrite/analogRead @mjs513 and I added/modified the device tree for this board, with the tables to support PWM (analogWrite) and analogRead on some of the Analog pins. Note: there are some issues with A4/A5 in that those pins are also on the same pins that support SPI. And when SPI is enabled, the GPIOC pin configuration is setup by the device tree to be MODER to be set for Alternat function and their AF set to 5. The analogRead code does not does not update these tables and as such analogRead fails. We found that if y ou disable SPI then they work better. I currently left the SPI enabled. Probably need to add something that when analogRead is called that it updates the GPIO registers to make it work. I am ecurrently experimenting with a hack in my test sketch that appears to change the MODER of those pins back to 3, but so far that does not appear to be sufficent: ``` static const struct gpio_dt_spec arduino_pins[] = {DT_FOREACH_PROP_ELEM_SEP( DT_PATH(zephyr_user), digital_pin_gpios, GPIO_DT_SPEC_GET_BY_IDX, (, ))}; void pinModeAnalog(pin_size_t pinNumber) { gpio_pin_configure_dt(&arduino_pins[pinNumber], GPIO_INPUT /*| GPIO_ACTIVE_HIGH */ | GPIO_MODE_ANALOG); } ``` On the analogWrites, this code has optionally in place that allows duplicate pins in the device tree GPIO list, by changing how I read in the PWM table from the Tree, instead of summing all of the matches in the GPIO tree, it instead saves the GPIO Port and pin number and uses them for the compare. Again this depends on if we wish for the Pin numbers for the functions like digitalRead/digitalWrite to match those used by the MBED version. I still have the last 3 truncated K5-K7 which are used by the LEDs and fault but depending on directions, can find other solutions. enable spi2 --- cores/arduino/zephyrCommon.cpp | 34 ++- loader/boards/arduino_portenta_h7_m7.conf | 4 +- loader/boards/arduino_portenta_h7_m7.overlay | 203 +++++++++++++++++- .../arduino_portenta_h7/pure_analog_pins.cpp | 17 ++ .../arduino_portenta_h7/pure_analog_pins.h | 57 +++++ variants/arduino_portenta_h7/variant.h | 1 + 6 files changed, 300 insertions(+), 16 deletions(-) create mode 100644 variants/arduino_portenta_h7/pure_analog_pins.cpp create mode 100644 variants/arduino_portenta_h7/pure_analog_pins.h diff --git a/cores/arduino/zephyrCommon.cpp b/cores/arduino/zephyrCommon.cpp index 4dd834cf..3263d8d2 100644 --- a/cores/arduino/zephyrCommon.cpp +++ b/cores/arduino/zephyrCommon.cpp @@ -140,6 +140,29 @@ const struct pwm_dt_spec arduino_pwm[] = { DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), pwms, PWM_DT_SPEC) }; /* pwm-pins node provides a mapping digital pin numbers to pwm channels */ +#if 1 +static const struct gpio_dt_spec arduino_pwm_pins[] = {DT_FOREACH_PROP_ELEM_SEP( + DT_PATH(zephyr_user), pwm_pin_gpios, GPIO_DT_SPEC_GET_BY_IDX, (, ))}; + +size_t pwm_pin_index(pin_size_t pinNumber) { + printk("pwm_pin_index: %u: ", pinNumber); + if (pinNumber >= ARRAY_SIZE(arduino_pins)) { + return (size_t)-1; + } + printk("(%p %u):", arduino_pins[pinNumber].port, arduino_pins[pinNumber].pin); + for(size_t i=0; i; + + pwm1: pwm { + status = "okay"; + pinctrl-0 = <&tim1_ch1_pk1 &tim1_ch2_pj11>; + pinctrl-names = "default"; + }; }; -&dma1 { +&timers3 { + status = "okay"; + st,prescaler = <100>; + + pwm3: pwm { + status = "okay"; + pinctrl-0 = <&tim3_ch1_pc6 &tim3_ch2_pc7>; + pinctrl-names = "default"; + }; +}; + +&timers8 { + status = "okay"; + st,prescaler = <100>; + + pwm8: pwm { + status = "okay"; + pinctrl-0 = <&tim8_ch3n_ph15 &tim8_ch2_pj10 &tim8_ch2n_pj7>; + pinctrl-names = "default"; + }; +}; + +&timers12 { status = "okay"; + st,prescaler = <100>; + + pwm12: pwm { + status = "okay"; + pinctrl-0 = <&tim12_ch1_ph6>; + pinctrl-names = "default"; + }; +}; + +&pwm1 { + /* Use the pwmclock node to start the clock generation */ + pwmclock: pwmclock { + status = "okay"; + compatible = "pwm-clock"; + clock-frequency = <0>; + #clock-cells = <1>; + pwms = <&pwm1 2 PWM_HZ(12000000) PWM_POLARITY_NORMAL>; + }; }; &rng { status = "okay"; }; +&dmamux1 { + status = "okay"; +}; + +&dma1 { + status = "okay"; +}; + + +&adc1 { + pinctrl-0 = <&adc1_inp12_pc2 + &adc1_inp13_pc3 + &adc1_inp18_pa4 + &adc1_inp3_pa6 + &adc1_inp0_pa0_c + &adc1_inp1_pa1_c>; + pinctrl-names = "default"; + st,adc-clock-source = ; + st,adc-prescaler = <4>; + status = "okay"; + + #address-cells = <1>; + #size-cells = <0>; + + channel@c { + reg = <12>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <16>; + }; + channel@d { + reg = <13>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <16>; + }; + channel@12 { + reg = <18>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <16>; + }; + channel@3 { + reg = <3>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <16>; + }; + + /* PA0_C and PA1_C */ + channel@0 { + reg = <0>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <16>; + }; + channel@1 { + reg = <1>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <16>; + }; +}; + +&adc3 { + pinctrl-0 = <&adc3_inp0_pc2_c + &adc3_inp1_pc3_c>; + pinctrl-names = "default"; + st,adc-clock-source = ; + st,adc-prescaler = <4>; + status = "okay"; + + #address-cells = <1>; + #size-cells = <0>; + + channel@0 { + reg = <0>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <16>; + }; + channel@1 { + reg = <1>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <16>; + }; +}; + + / { chosen { zephyr,console = &usart6; @@ -293,20 +438,60 @@ <&gpiok 1 0>, <&gpiok 2 0>, <&gpiok 3 0>, - <&gpiok 4 0>, - <&gpiok 5 0>, - <&gpiok 6 0>, - <&gpiok 7 0>; + <&gpiok 4 0>; + + /* commented out for now to allow LEDs to work + /* <&gpiok 5 0>, */ + /* <&gpiok 6 0>, */ + /* <&gpiok 7 0>; */ builtin-led-gpios = <&gpiok 5 GPIO_ACTIVE_LOW>, - <&gpiok 6 GPIO_ACTIVE_LOW>, - <&gpiok 7 GPIO_ACTIVE_LOW>; - + <&gpiok 6 GPIO_ACTIVE_LOW>, + <&gpiok 7 GPIO_ACTIVE_LOW>; + + pwm-pin-gpios = //<&gpioa 8 0>, + <&gpioc 6 0>, + <&gpioc 7 0>, + //<&gpiog 7 0>, + <&gpioj 11 0>, + <&gpiok 1 0>, + <&gpioh 15 0>, + <&gpioj 7 0>, + <&gpioj 10 0>, + <&gpioh 6 0>; + + adc-pin-gpios = <&gpioz 0 0>, /* analog only */ + <&gpioz 1 0>, /* analog only */ + <&gpioz 2 0>, /* analog only */ + <&gpioz 3 0>, /* analog only */ + <&gpioc 2 0>, + <&gpioc 3 0>, + <&gpioa 4 0>, + <&gpioa 6 0>; + serials = <&cdc_acm_uart0>,<&usart6>, <&usart1>, <&uart4>; cdc-acm = <&cdc_acm_uart0>; i2cs = <&i2c3>, <&i2c1>, <&i2c4>; spis = <&spi2>; + pwms = //<&pwm8 1 PWM_HZ(500) PWM_POLARITY_NORMAL>, + <&pwm3 1 PWM_HZ(500) PWM_POLARITY_NORMAL>, + <&pwm3 2 PWM_HZ(500) PWM_POLARITY_NORMAL>, + <&pwm1 2 PWM_HZ(12000000) PWM_POLARITY_NORMAL>, + <&pwm1 1 PWM_HZ(5000) PWM_POLARITY_NORMAL>, + <&pwm8 1 PWM_HZ(500) PWM_POLARITY_INVERTED>, + <&pwm8 3 PWM_HZ(500) PWM_POLARITY_INVERTED>, + <&pwm8 2 PWM_HZ(500) PWM_POLARITY_NORMAL>, + <&pwm12 1 PWM_HZ(500) PWM_POLARITY_NORMAL>; + + io-channels = <&adc1 0>, + <&adc1 1>, + <&adc3 0>, + <&adc3 1>, + <&adc1 12>, + <&adc1 13>, + <&adc1 18>, + <&adc1 3>; }; }; diff --git a/variants/arduino_portenta_h7/pure_analog_pins.cpp b/variants/arduino_portenta_h7/pure_analog_pins.cpp new file mode 100644 index 00000000..83548487 --- /dev/null +++ b/variants/arduino_portenta_h7/pure_analog_pins.cpp @@ -0,0 +1,17 @@ +#include "pure_analog_pins.h" + +#undef A0 +#undef A1 +#undef A2 +#undef A3 + +PureAnalogPin A0_PURE(0); +PureAnalogPin A1_PURE(1); +PureAnalogPin A2_PURE(2); +PureAnalogPin A3_PURE(3); + +int getAnalogReadResolution(); + +int analogRead(PureAnalogPin pin) { + return ::analogRead(A0 + pin.get()); +} diff --git a/variants/arduino_portenta_h7/pure_analog_pins.h b/variants/arduino_portenta_h7/pure_analog_pins.h new file mode 100644 index 00000000..b949a069 --- /dev/null +++ b/variants/arduino_portenta_h7/pure_analog_pins.h @@ -0,0 +1,57 @@ +#ifndef _PURE_ANALOG_PINS_ +#define _PURE_ANALOG_PINS_ + +/****************************************************************************** + * INCLUDE + ******************************************************************************/ + +#include "Arduino.h" + +/****************************************************************************** + * PREPROCESSOR-MAGIC + ******************************************************************************/ + +#define PURE_ANALOG_AS_DIGITAL_ATTRIBUTE __attribute__ ((error("Can't use pins A0-A3 as digital"))) + +/****************************************************************************** + * TYPEDEF + ******************************************************************************/ + +class PureAnalogPin { +public: + PureAnalogPin(int _pin) : pin(_pin) {}; + int get() { + return pin; + }; + bool operator== (PureAnalogPin const & other) const { + return pin == other.pin; + } + //operator int() = delete; + __attribute__ ((error("Change me to a #define"))) operator int(); +private: + int pin; +}; + +extern PureAnalogPin A0_PURE; +extern PureAnalogPin A1_PURE; +extern PureAnalogPin A2_PURE; +extern PureAnalogPin A3_PURE; + +#define A0 A0_PURE +#define A1 A1_PURE +#define A2 A2_PURE +#define A3 A3_PURE + +/****************************************************************************** + * FUNCTION DECLARATION + ******************************************************************************/ + +void PURE_ANALOG_AS_DIGITAL_ATTRIBUTE pinMode (PureAnalogPin pin, PinMode mode); +PinStatus PURE_ANALOG_AS_DIGITAL_ATTRIBUTE digitalRead (PureAnalogPin pin); +void PURE_ANALOG_AS_DIGITAL_ATTRIBUTE digitalWrite(PureAnalogPin pin, PinStatus value); +int analogRead (PureAnalogPin pin); +void PURE_ANALOG_AS_DIGITAL_ATTRIBUTE analogWrite (PureAnalogPin pin, int value); + +#undef PURE_ANALOG_AS_DIGITAL_ATTRIBUTE + +#endif /* _PURE_ANALOG_PINS_ */ diff --git a/variants/arduino_portenta_h7/variant.h b/variants/arduino_portenta_h7/variant.h index 68c33a89..9c1abf2e 100644 --- a/variants/arduino_portenta_h7/variant.h +++ b/variants/arduino_portenta_h7/variant.h @@ -3,6 +3,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ +#include "pure_analog_pins.h" // TODO: correctly handle these legacy defines #define MOSI 0 From 8de31aefb03c56ba37833fde18fda69d8ac576c7 Mon Sep 17 00:00:00 2001 From: kurte Date: Fri, 7 Mar 2025 08:03:37 -0800 Subject: [PATCH 6/6] Update the PWM pin numbers so the numbers and indexes are in sync --- loader/boards/arduino_portenta_h7_m7.overlay | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/loader/boards/arduino_portenta_h7_m7.overlay b/loader/boards/arduino_portenta_h7_m7.overlay index 3a7a1786..55ffbd83 100644 --- a/loader/boards/arduino_portenta_h7_m7.overlay +++ b/loader/boards/arduino_portenta_h7_m7.overlay @@ -46,7 +46,7 @@ pwm1: pwm { status = "okay"; - pinctrl-0 = <&tim1_ch1_pk1 &tim1_ch2_pj11>; + pinctrl-0 = <&tim1_ch1_pa8 &tim1_ch2_pj11>; pinctrl-names = "default"; }; }; @@ -91,7 +91,8 @@ compatible = "pwm-clock"; clock-frequency = <0>; #clock-cells = <1>; - pwms = <&pwm1 2 PWM_HZ(12000000) PWM_POLARITY_NORMAL>; + pwms = <&pwm1 1 PWM_HZ(11000000) PWM_POLARITY_NORMAL>; + //12mhz for 7670, default is also 12MHz }; }; @@ -451,12 +452,12 @@ <&gpiok 6 GPIO_ACTIVE_LOW>, <&gpiok 7 GPIO_ACTIVE_LOW>; - pwm-pin-gpios = //<&gpioa 8 0>, + pwm-pin-gpios = <&gpioa 8 0>, <&gpioc 6 0>, <&gpioc 7 0>, //<&gpiog 7 0>, <&gpioj 11 0>, - <&gpiok 1 0>, + //<&gpiok 1 0>, <&gpioh 15 0>, <&gpioj 7 0>, <&gpioj 10 0>, @@ -475,13 +476,12 @@ cdc-acm = <&cdc_acm_uart0>; i2cs = <&i2c3>, <&i2c1>, <&i2c4>; spis = <&spi2>; - pwms = //<&pwm8 1 PWM_HZ(500) PWM_POLARITY_NORMAL>, + pwms = <&pwm1 1 PWM_HZ(11000000) PWM_POLARITY_NORMAL>, //12mhz default <&pwm3 1 PWM_HZ(500) PWM_POLARITY_NORMAL>, <&pwm3 2 PWM_HZ(500) PWM_POLARITY_NORMAL>, - <&pwm1 2 PWM_HZ(12000000) PWM_POLARITY_NORMAL>, - <&pwm1 1 PWM_HZ(5000) PWM_POLARITY_NORMAL>, - <&pwm8 1 PWM_HZ(500) PWM_POLARITY_INVERTED>, + <&pwm1 2 PWM_HZ(5000) PWM_POLARITY_NORMAL>, <&pwm8 3 PWM_HZ(500) PWM_POLARITY_INVERTED>, + <&pwm8 2 PWM_HZ(500) PWM_POLARITY_INVERTED>, <&pwm8 2 PWM_HZ(500) PWM_POLARITY_NORMAL>, <&pwm12 1 PWM_HZ(500) PWM_POLARITY_NORMAL>;