MX682X / Rewritten_Wire_for_DxCore

A rewritten Wire library for the DxCore and megaTinyCore
0 stars 1 forks source link

Can't get nnew DxCore serial to build: #5

Open SpenceKonde opened 2 years ago

SpenceKonde commented 2 years ago

In file included from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore/UART.h:30:0, from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore/Arduino.h:408, from C:\Users\Spence\AppData\Local\Temp\arduino_build_237143\sketch\sketch_nov15a.ino.cpp:1: C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore/UART_swap.h:181:36: error: 'HWSERIAL1_MUX_OFFSET' was not declared in this scope {HWSERIAL1_MUX_PINSWAP_NONE, HWSERIAL1_MUX_OFFSET, PORTMUX_USART1_gm} ^~~~~~~~ C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore/UART_swap.h:181:36: note: suggested alternative: 'HWSERIAL1_MUX_COUNT' {HWSERIAL1_MUX_PINSWAP_NONE, HWSERIAL1_MUX_OFFSET, PORTMUX_USART1_gm} ^~~~~~~~ HWSERIAL1_MUX_COUNT C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore/UART_swap.h:205:36: error: 'HWSERIAL2_MUX_OFFSET' was not declared in this scope {HWSERIAL2_MUX_PINSWAP_NONE, HWSERIAL2_MUX_OFFSET, PORTMUX_USART2_gm} ^~~~~~~~ C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore/UART_swap.h:205:36: note: suggested alternative: 'HWSERIAL2_MUX_COUNT' {HWSERIAL2_MUX_PINSWAP_NONE, HWSERIAL2_MUX_OFFSET, PORTMUX_USART2_gm} ^~~~~~~~ HWSERIAL2_MUX_COUNT

SpenceKonde commented 2 years ago

HWSERIAL1_MUX_OFFSET and the like - yeah they ain't defined anywhere, and where are they supposed to be defined and as what? I can't figure out where it's used in order to deduce that values uit wants....

Is that just group position? If so why not use the group position defines - those are defines, it's only the group codes that are enums

MX682X commented 2 years ago

The Dx Series might use 2 register for MUX, the pins_arduino.h files supply the base address PORTMUX.USARTA (or similar) for the Dx and PORTMUX.CTRLA (or similar) for the tinies. to keep everything as small as possible, the pins_arduino supply an offset, USART 4 and 5 are +1, making it to point to USARTB. Try the 48 pin version first. I didn't bother to do the rest should it be changed again.

P.S.: MUX_OFFSET is used in _mux_set() through a pgm_read

MX682X commented 2 years ago

48pin-standard.zip dang it, the changes were missing....

MX682X commented 2 years ago

If the changes are alright, I'm gonna change the other files as well

SpenceKonde commented 2 years ago

I'm now getting different errors....

In file included from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART0.cpp:27:0:
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART_private.h:32:1: error: prototype for 'UartClass::UartClass(volatile USART_t*, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t)' does not match any in class 'UartClass'
 UartClass::UartClass(
 ^~~~~~~~~
In file included from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\Arduino.h:408:0,
                 from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART0.cpp:25:
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART.h:134:7: error: candidates are: constexpr UartClass::UartClass(UartClass&&)
 class UartClass : public HardwareSerial {
       ^~~~~~~~~
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART.h:134:7: error:                 constexpr UartClass::UartClass(const UartClass&)
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART.h:167:12: error:                 UartClass::UartClass(volatile USART_t*, uint8_t*, uint8_t, uint8_t)
     inline UartClass(volatile USART_t *hwserial_module, uint8_t *usart_pins, uint8_t mux_count, uint8_t mux_defualt);
            ^~~~~~~~~
In file included from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART0.cpp:27:0:
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART_private.h:44:76: error: mixing declarations and function-definitions is forbidden
             { hwserial_rx_pin_swap, hwserial_tx_pin_swap, uart_mux_swap } },
                                                                            ^
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART_private.h:45:13: error: expected constructor, destructor, or type conversion before '(' token
     _pin_set(0),
             ^
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART_private.h:54:6: error: prototype for 'void UartClass::_rx_complete_irq()' does not match any in class 'UartClass'
 void UartClass::_rx_complete_irq(void)
      ^~~~~~~~~
In file included from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\Arduino.h:408:0,
                 from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART0.cpp:25:
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART.h:204:17: error: candidate is: static void UartClass::_rx_complete_irq(UartClass&)
     static void _rx_complete_irq(UartClass& uartClass);
                 ^~~~~~~~~~~~~~~~
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART.h:167:12: warning: inline function 'UartClass::UartClass(volatile USART_t*, uint8_t*, uint8_t, uint8_t)' used but never defined
     inline UartClass(volatile USART_t *hwserial_module, uint8_t *usart_pins, uint8_t mux_count, uint8_t mux_defualt);
            ^~~~~~~~~
In file included from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART1.cpp:27:0:
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART_private.h:32:1: error: prototype for 'UartClass::UartClass(volatile USART_t*, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t)' does not match any in class 'UartClass'
 UartClass::UartClass(
 ^~~~~~~~~
In file included from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\Arduino.h:408:0,
                 from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART1.cpp:25:
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART.h:134:7: error: candidates are: constexpr UartClass::UartClass(UartClass&&)
 class UartClass : public HardwareSerial {
       ^~~~~~~~~
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART.h:134:7: error:                 constexpr UartClass::UartClass(const UartClass&)
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART.h:167:12: error:                 UartClass::UartClass(volatile USART_t*, uint8_t*, uint8_t, uint8_t)
     inline UartClass(volatile USART_t *hwserial_module, uint8_t *usart_pins, uint8_t mux_count, uint8_t mux_defualt);
            ^~~~~~~~~
In file included from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART1.cpp:27:0:
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART_private.h:44:76: error: mixing declarations and function-definitions is forbidden
             { hwserial_rx_pin_swap, hwserial_tx_pin_swap, uart_mux_swap } },
                                                                            ^
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART_private.h:45:13: error: expected constructor, destructor, or type conversion before '(' token
     _pin_set(0),
             ^
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART_private.h:54:6: error: prototype for 'void UartClass::_rx_complete_irq()' does not match any in class 'UartClass'
 void UartClass::_rx_complete_irq(void)
      ^~~~~~~~~
In file included from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\Arduino.h:408:0,
                 from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART1.cpp:25:
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART.h:204:17: error: candidate is: static void UartClass::_rx_complete_irq(UartClass&)
     static void _rx_complete_irq(UartClass& uartClass);
                 ^~~~~~~~~~~~~~~~
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART.h:167:12: warning: inline function 'UartClass::UartClass(volatile USART_t*, uint8_t*, uint8_t, uint8_t)' used but never defined
     inline UartClass(volatile USART_t *hwserial_module, uint8_t *usart_pins, uint8_t mux_count, uint8_t mux_defualt);
            ^~~~~~~~~
In file included from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART3.cpp:27:0:
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART_private.h:32:1: error: prototype for 'UartClass::UartClass(volatile USART_t*, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t)' does not match any in class 'UartClass'
 UartClass::UartClass(
 ^~~~~~~~~
In file included from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\Arduino.h:408:0,
                 from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART3.cpp:25:
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART.h:134:7: error: candidates are: constexpr UartClass::UartClass(UartClass&&)
 class UartClass : public HardwareSerial {
       ^~~~~~~~~
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART.h:134:7: error:                 constexpr UartClass::UartClass(const UartClass&)
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART.h:167:12: error:                 UartClass::UartClass(volatile USART_t*, uint8_t*, uint8_t, uint8_t)
     inline UartClass(volatile USART_t *hwserial_module, uint8_t *usart_pins, uint8_t mux_count, uint8_t mux_defualt);
            ^~~~~~~~~
In file included from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART3.cpp:27:0:
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART_private.h:44:76: error: mixing declarations and function-definitions is forbidden
             { hwserial_rx_pin_swap, hwserial_tx_pin_swap, uart_mux_swap } },
                                                                            ^
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART_private.h:45:13: error: expected constructor, destructor, or type conversion before '(' token
     _pin_set(0),
             ^
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART_private.h:54:6: error: prototype for 'void UartClass::_rx_complete_irq()' does not match any in class 'UartClass'
 void UartClass::_rx_complete_irq(void)
      ^~~~~~~~~
In file included from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\Arduino.h:408:0,
                 from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART3.cpp:25:
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART.h:204:17: error: candidate is: static void UartClass::_rx_complete_irq(UartClass&)
     static void _rx_complete_irq(UartClass& uartClass);
                 ^~~~~~~~~~~~~~~~
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART.h:167:12: warning: inline function 'UartClass::UartClass(volatile USART_t*, uint8_t*, uint8_t, uint8_t)' used but never defined
     inline UartClass(volatile USART_t *hwserial_module, uint8_t *usart_pins, uint8_t mux_count, uint8_t mux_defualt);
            ^~~~~~~~~
In file included from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART.cpp:32:0:
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART_private.h:32:1: error: prototype for 'UartClass::UartClass(volatile USART_t*, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t)' does not match any in class 'UartClass'
 UartClass::UartClass(
 ^~~~~~~~~
In file included from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\Arduino.h:408:0,
                 from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART.cpp:29:
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART.h:134:7: error: candidates are: constexpr UartClass::UartClass(UartClass&&)
 class UartClass : public HardwareSerial {
       ^~~~~~~~~
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART.h:134:7: error:                 constexpr UartClass::UartClass(const UartClass&)
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART.h:167:12: error:                 UartClass::UartClass(volatile USART_t*, uint8_t*, uint8_t, uint8_t)
     inline UartClass(volatile USART_t *hwserial_module, uint8_t *usart_pins, uint8_t mux_count, uint8_t mux_defualt);
            ^~~~~~~~~
In file included from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART.cpp:32:0:
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART_private.h:44:76: error: mixing declarations and function-definitions is forbidden
             { hwserial_rx_pin_swap, hwserial_tx_pin_swap, uart_mux_swap } },
                                                                            ^
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART_private.h:45:13: error: expected constructor, destructor, or type conversion before '(' token
     _pin_set(0),
             ^
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART_private.h:54:6: error: prototype for 'void UartClass::_rx_complete_irq()' does not match any in class 'UartClass'
 void UartClass::_rx_complete_irq(void)
      ^~~~~~~~~
In file included from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\Arduino.h:408:0,
                 from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART.cpp:29:
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART.h:204:17: error: candidate is: static void UartClass::_rx_complete_irq(UartClass&)
     static void _rx_complete_irq(UartClass& uartClass);
                 ^~~~~~~~~~~~~~~~
Using previously compiled file: C:\Users\Spence\AppData\Local\Temp\arduino_build_889523\core\WMath.cpp.o
In file included from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART5.cpp:27:0:
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART_private.h:32:1: error: prototype for 'UartClass::UartClass(volatile USART_t*, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t)' does not match any in class 'UartClass'
 UartClass::UartClass(
 ^~~~~~~~~
In file included from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\Arduino.h:408:0,
                 from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART5.cpp:25:
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART.h:134:7: error: candidates are: constexpr UartClass::UartClass(UartClass&&)
 class UartClass : public HardwareSerial {
       ^~~~~~~~~
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART.h:134:7: error:                 constexpr UartClass::UartClass(const UartClass&)
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART.h:167:12: error:                 UartClass::UartClass(volatile USART_t*, uint8_t*, uint8_t, uint8_t)
     inline UartClass(volatile USART_t *hwserial_module, uint8_t *usart_pins, uint8_t mux_count, uint8_t mux_defualt);
            ^~~~~~~~~
In file included from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART5.cpp:27:0:
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART_private.h:44:76: error: mixing declarations and function-definitions is forbidden
             { hwserial_rx_pin_swap, hwserial_tx_pin_swap, uart_mux_swap } },
                                                                            ^
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART_private.h:45:13: error: expected constructor, destructor, or type conversion before '(' token
     _pin_set(0),
             ^
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART_private.h:54:6: error: prototype for 'void UartClass::_rx_complete_irq()' does not match any in class 'UartClass'
 void UartClass::_rx_complete_irq(void)
      ^~~~~~~~~
In file included from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\Arduino.h:408:0,
                 from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART5.cpp:25:
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART.h:204:17: error: candidate is: static void UartClass::_rx_complete_irq(UartClass&)
     static void _rx_complete_irq(UartClass& uartClass);
                 ^~~~~~~~~~~~~~~~
In file included from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART4.cpp:27:0:
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART_private.h:32:1: error: prototype for 'UartClass::UartClass(volatile USART_t*, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t)' does not match any in class 'UartClass'
 UartClass::UartClass(
 ^~~~~~~~~
In file included from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\Arduino.h:408:0,
                 from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART4.cpp:25:
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART.h:134:7: error: candidates are: constexpr UartClass::UartClass(UartClass&&)
 class UartClass : public HardwareSerial {
       ^~~~~~~~~
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART.h:134:7: error:                 constexpr UartClass::UartClass(const UartClass&)
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART.h:167:12: error:                 UartClass::UartClass(volatile USART_t*, uint8_t*, uint8_t, uint8_t)
     inline UartClass(volatile USART_t *hwserial_module, uint8_t *usart_pins, uint8_t mux_count, uint8_t mux_defualt);
            ^~~~~~~~~
In file included from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART2.cpp:27:0:
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART_private.h:32:1: error: prototype for 'UartClass::UartClass(volatile USART_t*, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t)' does not match any in class 'UartClass'
 UartClass::UartClass(
 ^~~~~~~~~
In file included from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART4.cpp:27:0:
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART_private.h:44:76: error: mixing declarations and function-definitions is forbidden
             { hwserial_rx_pin_swap, hwserial_tx_pin_swap, uart_mux_swap } },
                                                                            ^
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART_private.h:45:13: error: expected constructor, destructor, or type conversion before '(' token
     _pin_set(0),
             ^
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART_private.h:54:6: error: prototype for 'void UartClass::_rx_complete_irq()' does not match any in class 'UartClass'
 void UartClass::_rx_complete_irq(void)
      ^~~~~~~~~
In file included from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\Arduino.h:408:0,
                 from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART4.cpp:25:
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART.h:204:17: error: candidate is: static void UartClass::_rx_complete_irq(UartClass&)
     static void _rx_complete_irq(UartClass& uartClass);
                 ^~~~~~~~~~~~~~~~
In file included from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\Arduino.h:408:0,
                 from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART2.cpp:25:
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART.h:134:7: error: candidates are: constexpr UartClass::UartClass(UartClass&&)
 class UartClass : public HardwareSerial {
       ^~~~~~~~~
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART.h:134:7: error:                 constexpr UartClass::UartClass(const UartClass&)
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART.h:167:12: error:                 UartClass::UartClass(volatile USART_t*, uint8_t*, uint8_t, uint8_t)
     inline UartClass(volatile USART_t *hwserial_module, uint8_t *usart_pins, uint8_t mux_count, uint8_t mux_defualt);
            ^~~~~~~~~
In file included from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART2.cpp:27:0:
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART_private.h:44:76: error: mixing declarations and function-definitions is forbidden
             { hwserial_rx_pin_swap, hwserial_tx_pin_swap, uart_mux_swap } },
                                                                            ^
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART_private.h:45:13: error: expected constructor, destructor, or type conversion before '(' token
     _pin_set(0),
             ^
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART_private.h:54:6: error: prototype for 'void UartClass::_rx_complete_irq()' does not match any in class 'UartClass'
 void UartClass::_rx_complete_irq(void)
      ^~~~~~~~~
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART.h:167:12: warning: inline function 'UartClass::UartClass(volatile USART_t*, uint8_t*, uint8_t, uint8_t)' used but never defined
     inline UartClass(volatile USART_t *hwserial_module, uint8_t *usart_pins, uint8_t mux_count, uint8_t mux_defualt);
            ^~~~~~~~~
In file included from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\Arduino.h:408:0,
                 from C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART2.cpp:25:
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART.h:204:17: error: candidate is: static void UartClass::_rx_complete_irq(UartClass&)
     static void _rx_complete_irq(UartClass& uartClass);
                 ^~~~~~~~~~~~~~~~
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore\UART.h:167:12: warning: inline function 'UartClass::UartClass(volatile USART_t*, uint8_t*, uint8_t, uint8_t)' used but never defined
     inline UartClass(volatile USART_t *hwserial_module, uint8_t *usart_pins, uint8_t mux_count, uint8_t mux_defualt);
            ^~~~~~~~~
Using library Wire at version 2.0.1 in folder: C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\libraries\Wire 
exit status 1
Error compiling for board AVR DB-series (Optiboot).
SpenceKonde commented 2 years ago

Is there some other file I'm missing the right version of? And isn't the offset being used to determine the register that's in it's own define above?

SpenceKonde commented 2 years ago

AAaha! I'd missed UART_private, and it now compiles successfully

SpenceKonde commented 2 years ago

I think I've gotten it working correctly now. I did some rewriting of your functions because I couldn't convince myself that they were working correctly, and because I was uncomfortable with using "any negative number" for "none" There's now a MUX_NONE defined, 0x80 numerically that I use to signal that that is to be set - though the semantics may change... tried to rip as many defines out of the variant files as were readily removable, since most of that information is just duplicating information in the io headers - ya know like "If there's a USART0, we HAVE_HWSERIAL0, and it's vectors are USART0_DRE_vect, and so on. Why they felt a need to enumerate those in variants when they, you know, don't vary, is beyond me. I fixed the problem with the setting macros too, and laid the groundwork for the new features I wanted to do relating to RS485. Things are shaping up nicely. I gave in and started taking full advantage of the fact that for all Dx and Ex parts - I explicitly test use that in a few places. the trick with word reads is clever, I hadn't realized the ompiler missed that, though I'm not surprised, having seen what it does to my bitshift division in wiring.c.

MX682X commented 2 years ago

duplicating information in the io headers Don't forget that we are working here with a code that had to run on the old AVR core, 32-Bit ARM core and the new AVR core. They had to think of a io files independent solution. Working with only one COU architecture makes things easier, of course.

MX682X commented 2 years ago

I just remembered something: I think the 32u4/Leonardo was using the HAVEHWSERIAL define, since Serial0 was the USB serial, emulated by software, the hardware Serial is called Serial 1 and is even using xxx1 named registers. Who knows how the DU series will be implemented....

SpenceKonde commented 2 years ago

DU-series if the pulled brief is accurate will have a USART0 and USART1. What they had to sacrifice to USB was the TCD and it's PLL. But that can be entirely acomodated by my changes. I guess some of the code that generates the swap table would need to be adjusted if it assumes that there are no cases where USARTn exists whike USART n-1 doesn't - but there's no indication that will happen or could happen any time soon so we can burn that bridge when we come to it.

SpenceKonde commented 2 years ago

A comment on your comment in the .cpp file:

asm volatile ( "MOVW R30, %0 \n\t" // make sure the uartClass is actually in Z "LDD R28, Z+12 \n\t" // load USART module pointer "LDD R29, Z+13 \n\t" // same as above, high byte "LDI R18, 0x40 \n\t" // load USART_TXCIF_bm "STD Y+4, R18 \n\t" // and store to STATUS "STD Y+2, %1 \n\t" // store c "LDD R18, Z+21 \n\t" // load head "CPSE R18, %2 \n\t" // compare with new tail "RJMP end \n\t" "LDD R18, Y+5 \n\t" // load CTRLA "ANDI R18, 0xDF \n\t" // &= (~USART_DREIE_bm) "STD Y+5, R18 \n\t" // store to CTRLA "end: \n\t" "STD Z+22, %2 \n\t" // store new tail to uartClass._tx_buffer_tail : : "m" (uartClass), "r" (c), "r" (txTail) : "r18", "r28", "r29", "r30", "r31" );

First off, uh - why not just, like, pass the pointer in the z register by specifying that you need it in "z"?

But that doesn't exactly solve the problem - a big part of the problem is that the actual ISR calls a function. That is, the problem isn't just this:

_tx_data_empty_irq():
 48a: cf 93         push  r28
 48c: df 93         push  r29
 48e: fc 01         movw  r30, r24
 490: a4 85         ldd r26, Z+12 ; 0x0c
 492: b5 85         ldd r27, Z+13 ; 0x0d
 494: 96 89         ldd r25, Z+22 ; 0x16
 496: ef 01         movw  r28, r30
 498: c9 0f         add r28, r25
 49a: d1 1d         adc r29, r1
 49c: c9 5a         subi  r28, 0xA9 ; 169
 49e: df 4f         sbci  r29, 0xFF ; 255
 4a0: 88 81         ld  r24, Y
 4a2: 20 e4         ldi r18, 0x40 ; 64
 4a4: 14 96         adiw  r26, 0x04 ; 4    // Yeesh, I see why this makes you want to reimplement it.
 4a6: 2c 93         st  X, r18             // I remember reading that the way the X register is understood by the compiler
 4a8: 14 97         sbiw  r26, 0x04 ; 4    // and uses all three pointer registers like thy could displace, and the 
 4aa: 12 96         adiw  r26, 0x02 ; 2    // virtual ldd/std instructions then get transmuted into this crap. 
 4ac: 8c 93         st  X, r24
 4ae: 12 97         sbiw  r26, 0x02 ; 2
 4b0: 9f 5f         subi  r25, 0xFF ; 255
 4b2: 9f 73         andi  r25, 0x3F ; 63
 4b4: 85 89         ldd r24, Z+21 ; 0x15
 4b6: 89 13         cpse  r24, r25
 4b8: 06 c0         rjmp  .+12      ; 0x4c6 <UartClass::_tx_data_empty_irq(UartClass&)+0x3c>
 4ba: 15 96         adiw  r26, 0x05 ; 5
 4bc: 8c 91         ld  r24, X
 4be: 15 97         sbiw  r26, 0x05 ; 5
 4c0: 8f 7d         andi  r24, 0xDF ; 223
 4c2: 15 96         adiw  r26, 0x05 ; 5
 4c4: 8c 93         st  X, r24
 4c6: 96 8b         std Z+22, r25 ; 0x16
 4c8: df 91         pop r29
 4ca: cf 91         pop r28
 4cc: 08 95         ret

It's also that it gets called by this:

00000882 <__vector_22>:
__vector_22():
 882: 1f 92         push  r1
 884: 0f 92         push  r0
 886: 0f b6         in  r0, 0x3f  ; 63
 888: 0f 92         push  r0
 88a: 11 24         eor r1, r1
 88c: 0b b6         in  r0, 0x3b  ; 59
 88e: 0f 92         push  r0
 890: 2f 93         push  r18
 892: 3f 93         push  r19
 894: 4f 93         push  r20
 896: 5f 93         push  r21
 898: 6f 93         push  r22
 89a: 7f 93         push  r23
 89c: 8f 93         push  r24
 89e: 9f 93         push  r25
 8a0: af 93         push  r26
 8a2: bf 93         push  r27
 8a4: ef 93         push  r30
 8a6: ff 93         push  r31
 8a8: 8c ec         ldi r24, 0xCC ; 204
 8aa: 90 e4         ldi r25, 0x40 ; 64
 8ac: ee dd         rcall .-1060    ; 0x48a <UartClass::_tx_data_empty_irq(UartClass&)>
 8ae: ff 91         pop r31
 8b0: ef 91         pop r30
 8b2: bf 91         pop r27
 8b4: af 91         pop r26
 8b6: 9f 91         pop r25
 8b8: 8f 91         pop r24
 8ba: 7f 91         pop r23
 8bc: 6f 91         pop r22
 8be: 5f 91         pop r21
 8c0: 4f 91         pop r20
 8c2: 3f 91         pop r19
 8c4: 2f 91         pop r18
 8c6: 0f 90         pop r0
 8c8: 0b be         out 0x3b, r0  ; 59
 8ca: 0f 90         pop r0
 8cc: 0f be         out 0x3f, r0  ; 63
 8ce: 0f 90         pop r0
 8d0: 1f 90         pop r1
 8d2: 18 95         reti

Notice that the function doesn't use r19, r20, r21, r22 or r23. Or r0, for that matter. 0x3b is RAMPZ. Sometimes it likes to save and restore that one too. I dunno on what criteria either, since I swear i've seen interrupts not save and restore it shrug but it does even on 128k parts That doesnt matter - they're call used they get saved and restored. And r1 is always saved, cleared and restored unless the ISR is naked - which does make sense, at least. To bring joy to people on small-flash parts, there's one of those bloated things for both ISRs on each serial port. Whatyou eant to do is implement it in full assembly with single routine that handkes all cases reasonably efficientlky,

I think I have a solution though - though it's a little scary how I enter it. It relies on two dubious things which I've done elsewhere, though not extensively. They are: Jumps and calls from anywhere to anywhere seem to work, regardless of what file the label is in, I thought there were restrictions, but it doesn;t seem like there are. M Flash library is able to call EntryPointSPM by name successfully (I thought I'd have to figure out a way to get it's address, but nope, worked fine... o_o. to wrrite toall but the first5bit512b of flas yiu need to be executing from the first 512b (BOOTSIZE=1, if there is no biotlkioader involved, ) has to be located in .trampolines because I needed to find a section that would always be in the first 512b because I needed the fake bootloader section to be as small as possible to maximize the flexibility of the no-restrictions flash from app mode. But putting it in init didn't do that if the user had variables declared PROGMEM. I dunno what is supposed to go there, but whatever it is, it's more important to the linker to put those things at low addresses than progmem, but progmem is more importnt to keep at low address than .initn. (That rjmp is there so that if/when execution stumbles onto this, it'll jump over it instead of trying to write r0 and r1 to whatever location in flash the z is pointing at and then return to wherever the top two bytes of the stack point to, probably 0000 leading to a bootloop at startup)

  void __spm_entrypoint (void) __attribute__ ((naked)) __attribute__((used)) __attribute__ ((section (".trampolines")));
  void __spm_entrypoint (void)
  {
    __asm__ __volatile__(
              "rjmp .+4"                "\n\t" // Jump over this if we got here the wrong way
             "EntryPointSPM:"           "\n\t" // this is the label we call
              "spm z+"                  "\n\t" // write r0, r1 to location pointed to by r30,r31, with post increment
              "ret"::);                        // and then return.
  }

The part which is definitely sketchy is ducking out of assembly to grab a global variable address in a constraint and immediately returning asm, while ((naked)) and unable to actually do anything safely in c; it seems to work - all that we need the compiler to do is generate 2 LDI's, we just don't know what they are a priori. I do it to grab the function table pointer in my split-apart attachInterrupt kludge in the same way (refer to the github version not the released version, as I looked at it today and fixed some problems, and because I'd forgotten I could jump to labels no matter where they were I was working around that instead of just jumping. )

So here my thinking: Declare the ISRs that exist in multiplicate and need to all run one function with NAKED_ISR(). Each one goes something like:

NAKED_ISR(HWSERIAL0_DRE_VECTOR) { asm volatile ( "push r30" "\n\t" // push the z reg onto stack within this "push r31" "\n\t" // block of assenbly, gotta make room... : // then drop back into C, sort of... : // but all you do there is grab ); // the address of the object by passing asm volatile ( // it to inline assembly in the z "jmp HWSerialDREISR" // : // : "z" (Serial0) // ); }

So then, your actual isr, is a function declared (naked) (used) and all it has in it is yet another block of inline assembly and you should find the class instance address in Z....

void asm volatile ( "HWSerialDREISR:" "\n\t" // "push r18" "\n\t" // "in r18, 0x3F" "\n\t" // save sreg "push r18" "\n\t" // (also need to save clear and restore r1 if using that or mul insn) "push r19" "\n\t" // tail goes here "push r20" "\n\t" // and the character can go here "push r28" "\n\t" // "push r29" "\n\t" // "ldd r19, Z+22" "\n\t" // okay, "tail to r19"? Okay, tail to r19... //.. somehow find character we want to send .... // (I don't know how you know that the usart module is // at +12 and +13, head at +21 and tail at +22.) // and put it into r20, then pick up from your code "ldd r28, Z+12" "\n\t" // load USART module pointer "ldd r29, Z+13" "\n\t" // same as above, high byte "ldi r18, 0x40" "\n\t" // load USART_TXCIF_bm "std Y+4, r18" "\n\t" // and store to STATUS "std Y+2, r20" "\n\t" // store c "inc r19" "\n\t" // increment tail - unless done above "andi r19, 63" "\n\t" // 64b buffer wraparound - continue your code "ldd r18, Z+21" "\n\t" // load head "cpse r18, %2" "\n\t" // compare with new tail "rjmp DREend" "\n\t" // "ldd r18, Y+5" "\n\t" // load CTRLA "andi r18, 0xDF" "\n\t" // &= (~USART_DREIE_bm) "std Y+5, r18" "\n\t" // store to CTRLA "DREend:" "\n\t" // "std Z+22, %2" "\n\t" // store new tail to uartClass._tx_buffer_tail "pop r29" "\n\t" // now, we're naked so we have to clean up "pop r28" "\n\t" // pop everything pushed in reverse order "pop r20" "\n\t" // "pop r19" "\n\t" // "pop r18" "\n\t" // "out 0x3F" "\n\t" // restore the SREG "pop r18" "\n\t" // "pop r31" "\n\t" // Now clean up after the naked isr "pop r30" "\n\t" // so the rest of the app won't know "reti" "\n" // and execute a reti.... ); Is this approach sound?



Working on support for the #1 most requesredNow, won't oovk back at thuis untikl that's ready. 

By the way, do you have any idea about whym rrght before the DxCore 1.3.7 release, assembler listingopped opped demangling and source code uuincluded? It is severely interfering with my ability to maintain the core and work on these issues, but I just copied that functionality verbatim and it worked for 4 years. Now no more source included. WTF haooened? I have no understanding of if exoperience with setting up and configuring the  build environment, nd I just don't know what it is that I might have done. It was working up unytil nrarly thre end of 1.3.7 development, and was broken from there on akl later builds...  

I don't even know if it's just broken for me, or impacgs all users!

Any ideas on that? like I said, no clue about how to approach that, and th I can't maintain this core the way I want and need to without it
MX682X commented 2 years ago

First off, uh - why not just, like, pass the pointer in the z register by specifying that you need it in "z"?

Because The compiler was putting the pointer to the Serial object in r24&r25 iirc. It was easier to do this way to test if the function itself was working. Also, I didn't knew I could just use 'z' in the assembler code, it was basically the first time I wrote code in assembler.

// (I don't know how you know that the usart module is // at +12 and +13, head at +21 and tail at +22.)

This is the tricky part. For the example I grabbed it from what the compiler generated and noticed that there was a weird offset of +6. This +6 comes from the print class that saves an uin32_t millis for timeout and some vPointer (thank you, AS7 debugger) And the other offset of +12 is -6 from print leaving 6 bytes what represents the offset in the UART class if you count the variable sizes. The tricky thing is, and one of the reasons why I would rather not do it in assembler, if one were to change just the order of the variables, it might break the whole assembly part. So before doing that, we need to find a way to automatically generate the offsets. Or do some checks, is the pointer of the USART module still +12 bytes from the UART class?

Is this approach sound?

Basically, yes, that is what I was thinking about doing. Except, that we have to keep it an actual function with CALL (I thought about using ICALL and that's why I wanted to keep Z register unused in the first drafts, but now I realized it will be worse then CALL since that means we have to load two bytes in the Z register). This part of code is also called by flush, meaning we can't put a reti at the end of it, the reti has to stay in the ISR.

By the way, do you have any idea about whym rrght before the DxCore 1.3.7 release, assembler listingopped opped demangling and source code uuincluded? It is severely interfering with my ability to maintain the core and work on these issues, but I just copied that functionality verbatim and it worked for 4 years. Now no more source included. WTF haooened? I have no understanding of if exoperience with setting up and configuring the build environment, nd I just don't know what it is that I might have done. It was working up unytil nrarly thre end of 1.3.7 development, and was broken from there on akl later builds...

Sorry, I have troubble following, there is too much cat inteference on the line... (at least I hope so)

SpenceKonde commented 2 years ago

Okay so my suspicion that figuring out the offsets within the UsartClass structure is the hard part is correct it sounds like. I may come back to this when done with the other stuff

argh, Yeah that's not Zuzu's fault. Sometimes when tired, my hands stop syncing up well with what I want to type, though it still feels like I'm hitting the right keys and if I don't have auto-spellcheck, the result is crap like that; I typed that out in a text editor and copy/pasted so it didn't get spell checked.

By the way, do you have any idea about why right before the DxCore 1.3.7 release, assembler listing stopped demangling and including source code? It is severely interfering with my ability to maintain the core and work on these issues, but I just copied that functionality (assembly listing generation) verbatim and it worked for 4 years, without any issues. Now out of nowhere, bang, no more source included. WTF happened? I have no understanding of or experience with setting up and configuring the build environment, and I just don't know what it is that I might have done that has resulted in it not seeing the source files when generating the assembly listing or how to approach debugging it. It was working up until nearly the end of 1.3.7 development, since I used it to do the assembly optimization of a the bitshift division in wiring.c, but it is broken in all the released versions and development version.

MX682X commented 2 years ago

What is the assembler listing you are talking about? Are that the assembler file that the compiler generates? If so, The Arduino IDE is still generating a .lst file with the code in the build directory (/AppData/Local/Temp/arduino_build_xxxxxx/)

SpenceKonde commented 2 years ago

While trying to get an example for you I learned something important about this issue....

It only happens on optiboot boards. Sometimes about those confuses objdump o_o

I posted example output showing the two different blocks of output - if the build is for an optiboot definion, it doesn't use the core files....

https://github.com/SpenceKonde/DxCore/issues/190

SpenceKonde commented 2 years ago

Look at this MESS that avr-gcc is shitting out: from

  //volatile USART_t* MyUSART                = _hwserial_module;
  (*_hwserial_module).CTRLA       = ctrla;
  (*_hwserial_module).CTRLB       = 0;
  (*_hwserial_module).CTRLC       = (uint8_t) options;
  (*_hwserial_module).BAUD        = baud_setting;
  // Set USART mode of operation
  if (options & SERIAL_EVENT_RX) {
    setpinmask          &= 0x7F; // Remove the RX pin in this case because we get the input from elsewhere.
    (*_hwserial_module).EVCTRL    = 1;    // enable event input - not clear from datasheet what's needed to
    (*_hwserial_module).TXPLCTRL  = 0xFF; // Disable pulse length encoding.
  } else {
    (*_hwserial_module).EVCTRL    = 0;
  }
  (*_hwserial_module).CTRLB = ctrlb;
  _set_pins(_usart_pins, _mux_count, _pin_set, setpinmask);
  SREG=oldSREG;

we get....

C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore/UART.cpp:227
  //volatile USART_t* MyUSART                = _hwserial_module;
  (*_hwserial_module).CTRLA       = ctrla;
     9fe:   ec 85           ldd r30, Y+12   ; 0x0c
     a00:   fd 85           ldd r31, Y+13   ; 0x0d
     a02:   05 83           std Z+5, r16    ; 0x05
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore/UART.cpp:228
  (*_hwserial_module).CTRLB       = 0;
     a04:   ec 85           ldd r30, Y+12   ; 0x0c
     a06:   fd 85           ldd r31, Y+13   ; 0x0d
     a08:   16 82           std Z+6, r1 ; 0x06
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore/UART.cpp:229
  (*_hwserial_module).CTRLC       = (uint8_t) options;
     a0a:   ec 85           ldd r30, Y+12   ; 0x0c
     a0c:   fd 85           ldd r31, Y+13   ; 0x0d
     a0e:   e7 82           std Z+7, r14    ; 0x07
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore/UART.cpp:230
  (*_hwserial_module).BAUD        = baud_setting;
     a10:   ec 85           ldd r30, Y+12   ; 0x0c
     a12:   fd 85           ldd r31, Y+13   ; 0x0d
     a14:   20 87           std Z+8, r18    ; 0x08
     a16:   31 87           std Z+9, r19    ; 0x09
     a18:   ec 85           ldd r30, Y+12   ; 0x0c
     a1a:   fd 85           ldd r31, Y+13   ; 0x0d
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore/UART.cpp:232
  // Set USART mode of operation
  if (options & SERIAL_EVENT_RX) {
     a1c:   f5 fe           sbrs    r15, 5
     a1e:   b9 c0           rjmp    .+370       ; 0xb92 <UartClass::begin(unsigned long, unsigned int)+0x20e>
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore/UART.cpp:233
    setpinmask          &= 0x7F; // Remove the RX pin in this case because we get the input from elsewhere.
     a20:   8f 77           andi    r24, 0x7F   ; 127
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore/UART.cpp:234
    (*_hwserial_module).EVCTRL    = 1;    // enable event input - not clear from datasheet what's needed to
     a22:   91 e0           ldi r25, 0x01   ; 1
     a24:   94 87           std Z+12, r25   ; 0x0c
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore/UART.cpp:235
    (*_hwserial_module).TXPLCTRL  = 0xFF; // Disable pulse length encoding.
     a26:   ec 85           ldd r30, Y+12   ; 0x0c
     a28:   fd 85           ldd r31, Y+13   ; 0x0d
     a2a:   9f ef           ldi r25, 0xFF   ; 255
     a2c:   95 87           std Z+13, r25   ; 0x0d
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore/UART.cpp:239
  } else {
    (*_hwserial_module).EVCTRL    = 0;
  }
  (*_hwserial_module).CTRLB = ctrlb;
     a2e:   ec 85           ldd r30, Y+12   ; 0x0c
     a30:   fd 85           ldd r31, Y+13   ; 0x0d
     a32:   16 83           std Z+6, r17    ; 0x06
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore/UART.cpp:240
  _set_pins(_usart_pins, _mux_count, _pin_set, setpinmask);
     a34:   99 89           ldd r25, Y+17   ; 0x11
     a36:   b8 89           ldd r27, Y+16   ; 0x10
     a38:   2e 85           ldd r18, Y+14   ; 0x0e
     a3a:   3f 85           ldd r19, Y+15   ; 0x0f

but just uncommenting the MyUSART and using that instead:

C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore/UART.cpp:226
  volatile USART_t* MyUSART                = _hwserial_module;
     a0c:   d8 01           movw    r26, r16
     a0e:   1c 96           adiw    r26, 0x0c   ; 12
     a10:   ed 91           ld  r30, X+
     a12:   fc 91           ld  r31, X
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore/UART.cpp:227
  (*MyUSART).CTRLA       = ctrla;
     a14:   d5 83           std Z+5, r29    ; 0x05
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore/UART.cpp:228
  (*MyUSART).CTRLB       = 0;
     a16:   16 82           std Z+6, r1 ; 0x06
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore/UART.cpp:229
  (*MyUSART).CTRLC       = (uint8_t) options;
     a18:   e7 82           std Z+7, r14    ; 0x07
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore/UART.cpp:230
  (*MyUSART).BAUD        = baud_setting;
     a1a:   20 87           std Z+8, r18    ; 0x08
     a1c:   31 87           std Z+9, r19    ; 0x09
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore/UART.cpp:232
  // Set USART mode of operation
  if (options & SERIAL_EVENT_RX) {
     a1e:   f5 fe           sbrs    r15, 5
     a20:   b5 c0           rjmp    .+362       ; 0xb8c <UartClass::begin(unsigned long, unsigned int)+0x208>
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore/UART.cpp:233
    setpinmask          &= 0x7F; // Remove the RX pin in this case because we get the input from elsewhere.
     a22:   8f 77           andi    r24, 0x7F   ; 127
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore/UART.cpp:234
    (*MyUSART).EVCTRL    = 1;    // enable event input - not clear from datasheet what's needed to
     a24:   91 e0           ldi r25, 0x01   ; 1
     a26:   94 87           std Z+12, r25   ; 0x0c
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore/UART.cpp:235
    (*MyUSART).TXPLCTRL  = 0xFF; // Disable pulse length encoding.
     a28:   9f ef           ldi r25, 0xFF   ; 255
     a2a:   95 87           std Z+13, r25   ; 0x0d
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore/UART.cpp:239
  } else {
    (*MyUSART).EVCTRL    = 0;
  }
  (*MyUSART).CTRLB = ctrlb;
     a2c:   c6 83           std Z+6, r28    ; 0x06
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore/UART.cpp:240
  _set_pins(_usart_pins, _mux_count, _pin_set, setpinmask);
     a2e:   f8 01           movw    r30, r16
     a30:   91 89           ldd r25, Z+17   ; 0x11
     a32:   f0 88           ldd r15, Z+16   ; 0x10
     a34:   26 85           ldd r18, Z+14   ; 0x0e
     a36:   37 85           ldd r19, Z+15   ; 0x0f
_set_pins():
C:\Users\Spence\Documents\Arduino\hardware\DxCore\megaavr\cores\dxcore/UART.cpp:352
  *portmux       = temp;
#endif
}

And you can get it to do the adiw/st x/sbiw crap too depending on how the lines are organized.

Yargh....

MX682X commented 2 years ago

Well, technically, it does everything right. Afterall the _hwserial_module variable is a global volatile pointer, so the compiler is reloading it everytime, being afraid it might change. I think there was an Atmel pdf about how to make a local copy of volatile variables in ISRs to stop the compiler of loading it all the time.

Well, avr-gcc is technically open-source. One might try to change it up to at least optimize the X register operations, but I think this is a Pandora's box: Many bad things will pop up doing this, until we get the boon at the bottom of that. Also, I'll have some Exams in a couple of months so right now I'm trying to avoid starting any big project