MCUdude / MightyCore

Arduino hardware package for ATmega1284, ATmega644, ATmega324, ATmega324PB, ATmega164, ATmega32, ATmega16 and ATmega8535
Other
649 stars 182 forks source link

Add the ability to turn D1 into CLKO for the Atmega1284, 644, and 164 chips #213

Closed DrItanium closed 3 years ago

DrItanium commented 3 years ago

I have been using the atmega1284p as a chipset to interface with an intel i960Sx processor. One of the features of AVR chips is the ability to output the MCU clock signal through the CLKO pin. This pull request adds this ability through the clock speed menu in the arduino IDE.

From the commit log:

Most AVR chips provide the ability to emit the processor's clock cycle on a specific GPIO (the name provided is CLKO). This is done by changing some of the fuses at bootloader programming time. The upside is that the same clock that powers the microcontroller can be provided to other devices in your project.

The downside is that you lose the use of the CLKO pin as a GPIO.

I have exposed this option as a different speed grade for 16 and 20 MHz for the 1284, 644, and 164 Atmega chips. This ability isn't bound to just 16 and 20MHz speeds but I have no need for the other speeds in my own projects.

I also only exposed this for the 1284, 644, and 164 because those are the chips I actually own and can easily test. I did not want to expose the option on chips that I myself do not own and cause a problem for someone else.

MCUdude commented 3 years ago

Hi! I'm sorry, but this PR would most likely not get merged. Here's why:

; Run the following command to set fuses
; pio run -e fuses_bootloader -t fuses
; Run the following command to set fuses + burn bootloader
; pio run -e fuses_bootloader -t bootloader
[env:fuses_bootloader]
board_hardware.oscillator = external ; Oscillator type
board_hardware.uart = uart0          ; Set UART to use for serial upload
board_bootloader.speed = 115200      ; Set bootloader baud rate
board_hardware.bod = 2.7v            ; Set brown-out detection
board_hardware.eesave = yes          ; Preserve EEPROM when uploading using programmer
board_hardware.ckout = yes           ; Enable CLKO on pin PB1
upload_protocol = usbasp             ; Use the USBasp as programmer
upload_flags =                       ; Select USB as upload port and divide the SPI clock by 8
  -PUSB
  -B8
DrItanium commented 3 years ago

Oh cool! Thank you so much for the alternative. I'll look into that. No need to compute fuse values manually!