ATmega328PB Support

I’ve been working on an accessory/display board based around the ATmega328PB, mainly based around that it is one of the few small MCUs that was in stock anywhere. The 328PB is backwards compatible with 328P hex, but without the additional pins or devices.

One external hurdle is that avr-libc does not support the 328PB out-of-box (possibly due to avr-libc having not been actively maintained in years…), requiring a 2 line patch and 3 files from the Microchip ATmega device support pack.

It seems a 328PB branch for the extra pins existed back in 2019, if that can be resurrected, I’ll see about finishing and testing it.

I pushed that development branch back up to github (work-atmega328pb-20190924). Note that you would still need to compile for the atmega328p - just that now you should be able to access the additional PEx pins.

cd ~/klipper ; git fetch ; git checkout origin/work-atmega328pb-20190924 ; sudo service klipper stop ; make flash ; sudo service klipper start

Let me know your results (success or failure).

-Kevin

1 Like

Thanks. Got it compiling and flashing. Next I’ll need to build up a test board to verify functionality of the PE pins.

Also going to look in to the feasibility of adding support the additional i2c and spi interfaces.

Was this intentionally left PE0/PE1 instead of PE2/PE3?

That does appear to be a code error. I’ve updated and rebased that branch with it hopefully fixed.

Thanks,
-Kevin

Ok cool, I had thought so and changed it on my local already.

As-is, flashing doesn’t work due to the mismatch MCU name passed to avrdude vs the chip id. Even up adding the 328pb as a target. I’ll need to check if avrdude’s default config on the common distro’s has support for the 328pb, if not it’s just an additional switch on the avrdude call.

Good news, work-atmega328pb-20190924 is working as intended as far as the additional pins, ADC, and features common with the 328p. PE0-PE3 all worked as inputs. ADC functions as expected on PE2/PE3.

avrdude requires m328pb instead of m328p due to the chip id differences, but easy enough just to override that for make flash.

 make flash CONFIG_MCU=m328pb FLASH_DEVICE={...}

The second I2C and SPI interfaces, and additional timers would be nice, but I had no plans to make use of them and its not worth anybody’s effort.

The current changes in the branch are good to merge by me. :+1:

Thanks. I merged that change into the master Klipper branch.

-Kevin

1 Like