Port B gone missing

Port A is still there. But where has Port B gone to?

Please post code and error messages as text, using code tags, not as illegible screen shots.

Not much of a program.

void setup() {
  PORTA.DIRSET = PIN0_bm;  // set PA0 as output
  PORTB.DIRSET = PIN1_bm;  // set PB1 as output
}

void loop() {
  // put your main code here, to run repeatedly:
}
C:\Users\hanss\AppData\Local\Temp\.arduinoIDE-unsaved202483-261172-1n9bmks.l2zl\sketch_sep3a\sketch_sep3a.ino: In function 'void setup()':
C:\Users\hanss\AppData\Local\Temp\.arduinoIDE-unsaved202483-261172-1n9bmks.l2zl\sketch_sep3a\sketch_sep3a.ino:5:9: error: 'class PORTBClass' has no member named 'DIRSET'
 
         ^     

exit status 1

Compilation error: 'class PORTBClass' has no member named 'DIRSET'

The webserver doen't recognize the error messages as error messages.

Your code compiles successfully for me with 1.8.19.

Then there's a bug in Arduino IDE 2.3.2.

Compiles OK for me with 2.3.2 with register emulation set to none.

I can duplicate your error with register emulation set to ATMEGA328.

EDIT:
With 1.8.19 set to the ATMEGA328 emulation I can see the error as well.

I downloaded 1.8.19, it showed the same error.
I never set emulation ATMEGA328.
Maybe an update did that?

I think it is the default setting when opening up a new instance of the ide

So I need to remember to unset emulation 328 every time I open the IDE?

I prefer to use MegaCoreX with the NanoEvery rather than the Arduino megaAVR core. The register emulation is not an issue.

But with that core you need to set the pinout to "Nano Every". When you reopen the ide the selection is persistent.

Here’s my understanding now of the emulation: (correct me if I’m wrong)

When the compiler encounters PORTA.DIRSET it will search for PORTA in iom328.h, but PORTA is not present in the 328, so next search is in iom4809.h.

When the compiler encounters PORTB.DIRSET it will search for PORTB in iom328.h, finds something and tries to translate but can’t, resulting in a compiler error.

I’m used to Arduino IDE, but I will look into MegaCoreX later.

I never use emulation and don't know how it works behind the scenes.

There are two files in the core which are worth studying

NANO_compat.h
NANO_compat.cpp

I have a theory about when the emulation ATMEGA328 got set:

In the past I looked at an example sketch that had this emulation set.

When opening the IDE the last sketch comes back, the emulation setting persists with the sketch.

Selecting “new sketch”, the emulation setting persists.

And I don’t remember setting the emulation because it wasn’t me.

As for NANO_compat.cpp:

#ifdef AVR_NANO_4809_328MODE

#warning "ATMEGA328 registers emulation is enabled. You may encounter some speed issue. Please consider to disable it in the Tools menu"

...

If I had seen this warning…

I believe the default setting is in the board.txt file of the core

menu.mode=Registers emulation
nona4809.menu.mode.on=ATMEGA328
nona4809.menu.mode.on.build.328emulation=-DAVR_NANO_4809_328MODE
nona4809.menu.mode.off=None (ATMEGA4809)
nona4809.menu.mode.off.build.328emulation=

Use VPORTB and you won’t have a problem (and it’s faster!)

I doubt that code with VPORTB will compile with ATmega328 register emulation enabled.

It is indeed faster. And the old style PORTB_DIRSET works too.

But the problem undoubtedly extends to other registers.

I took it as a possible bug in the IDE. Maybe it can be perceived as a bug, but not in the place I suspected.

// emulation ATMEGA328 is set

void setup() {
  VPORTA.DIR |= PIN0_bm;   // set PA0 as output
  VPORTB.DIR |= PIN1_bm;   // set PB1 as output
  PORTA.DIRSET = PIN0_bm;  // set PA0 as output
  PORTB.DIRSET = PIN1_bm;  // set PB1 as output
}

void loop() {
  // put your main code here, to run repeatedly:
}
exit status 1

Compilation error: 'class PORTBClass' has no member named 'DIRSET'

Apparently VPORTB did well. PORTB not.
See also post #11.

I doubt that code with VPORTB will compile with ATmega328 register emulation enabled.

Why? It just #undef's the PORT registers and defines new PORT and DDR structures. It doesn't touch any of the other pre-defined symbols.

Why do you think that? The "Uno Compatibility" mode extends only to the PORT registers:

extern PORTBClass PORTB;
extern PORTCClass PORTC;
extern PORTDClass PORTD;
extern DDRBClass DDRB;
extern DDRCClass DDRC;
extern DDRDClass DDRD;

I took it as a possible bug in the IDE.

You can hardly provide "compatibility mode" without re-defining the symbols that need compatibility :frowning: So, "it's a feature."

You can look at the code that implement it, of course (OSSW!)

(I'm not confident that it makes much sense as a feature. Code that uses PORTB/etc usually does so for reasons of speed, and while the compatibility code is faster than digitalWrite(), it's not as fast as one would expect, especially for multi-bit usage.)