This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push: new ef04b4ccb6 boards/avr/atmega: Added Elegoo Mega2560r3 board support ef04b4ccb6 is described below commit ef04b4ccb64ecf9eb59b1dac8431a2234f06b960 Author: Matteo Golin <matteo.go...@gmail.com> AuthorDate: Sat May 24 23:18:23 2025 -0400 boards/avr/atmega: Added Elegoo Mega2560r3 board support Preliminary support for the Elegoo Mega2560r3 board by Elegoo with NSH configuration. --- .../boards/elegoo-mega2560r3/elegoo-mega2560r3.jpg | Bin 0 -> 174494 bytes .../avr/atmega/boards/elegoo-mega2560r3/index.rst | 120 +++++++++++++ boards/Kconfig | 12 ++ boards/avr/atmega/elegoo-mega2560r3/Kconfig | 4 + .../atmega/elegoo-mega2560r3/configs/nsh/defconfig | 42 +++++ .../avr/atmega/elegoo-mega2560r3/include/board.h | 88 +++++++++ .../avr/atmega/elegoo-mega2560r3/scripts/Make.defs | 37 ++++ .../avr/atmega/elegoo-mega2560r3/scripts/flash.ld | 200 +++++++++++++++++++++ boards/avr/atmega/elegoo-mega2560r3/src/Makefile | 31 ++++ boards/avr/atmega/elegoo-mega2560r3/src/avr_boot.c | 68 +++++++ boards/avr/atmega/elegoo-mega2560r3/src/avr_leds.c | 81 +++++++++ .../elegoo-mega2560r3/src/elegoo_mega2560r3.h | 53 ++++++ 12 files changed, 736 insertions(+) diff --git a/Documentation/platforms/avr/atmega/boards/elegoo-mega2560r3/elegoo-mega2560r3.jpg b/Documentation/platforms/avr/atmega/boards/elegoo-mega2560r3/elegoo-mega2560r3.jpg new file mode 100644 index 0000000000..2b3dcf1dc4 Binary files /dev/null and b/Documentation/platforms/avr/atmega/boards/elegoo-mega2560r3/elegoo-mega2560r3.jpg differ diff --git a/Documentation/platforms/avr/atmega/boards/elegoo-mega2560r3/index.rst b/Documentation/platforms/avr/atmega/boards/elegoo-mega2560r3/index.rst new file mode 100644 index 0000000000..e05e79764e --- /dev/null +++ b/Documentation/platforms/avr/atmega/boards/elegoo-mega2560r3/index.rst @@ -0,0 +1,120 @@ +==================== +Elegoo Mega2560 Rev3 +==================== + +.. tags:: chip:atmega2560, chip:atmega, arch:avr, vendor:elegoo, experimental + +.. figure:: elegoo-mega2560r3.jpg + :scale: 40 % + :align: center + :alt: The Elegoo Mega2560 Rev3 board with its included USB cable + + The Elegoo Mega2560 Rev3 board with its included USB cable + +This board is a variant of the `Arduino Mega2560 Rev3 board +<https://docs.arduino.cc/hardware/mega-2560/>`_ designed by Elegoo. The `product +listing can be found here +<https://us.elegoo.com/products/elegoo-mega-2560-r3-board>`_. + +Features +======== + +* Atmel ATMega2560 chip +* 54 digital pins +* 16 analog inputs +* 4 serial ports +* 4KB EEPROM + +.. warning:: + + The ATMega2560 chip supported is limited, and thus this board does not + support many peripherals. If you would like to help improve support for this + board and other ATMega2560-based boards, please see the :doc:`contributing + guidelines </contributing/index>`. + +Buttons and LEDs +================ + +The board has a large RESET button, which is not user controllable. + +There are 4 LEDs on-board the Elegoo Mega2560 Rev3: + +* ON: indicates active power, connected directly to the power supply +* TX: indicates transmitting data +* RX: indicates receiving data +* TEST: board controllable LED, near "PWM" label. Turns on to indicate that + NuttX started, and flashes at 1Hz to indicate panic. + +Pin Mapping +=========== + +The full pin-out of this board is the same as the Arduino Mega2560r3 pinout, +which can be found `here <https://docs.arduino.cc/hardware/mega-2560/>`_. + +Power Supply +============ + +This board uses 5V logic. It has on-board power regulation to provide 5V and +3.3V rails to the user. The 3.3V rail can only supply 50mA. + +The board can be powered a few different ways: + +* Via the USB connection at 5V +* Via external power supply to the barrel jack (center-positive) at 7V - 12V + +Installation +============ + +You will need the ``avrdude`` utility to flash this board. For instructions on +how to install the AVR toolchain, consult the main documentation for the AVR +architecture. + +Building NuttX +============== + +In order to build NuttX, you can follow the regular process of using +``./tools/configure.sh`` and ``make``. + +.. code:: console + + $ ./tools/configure.sh elegoo-mega2560r3:nsh + $ make + +The build system will generate a ``.hex`` file along with the typical ELF file. +If not, enable the ``CONFIG_INTELHEX_BINARY`` option. + +.. warning:: + + Beware of the small memory size of this board's chip when choosing what to + include in your NuttX image. + +Flashing +======== + +Then, to flash the board, connect it via USB to the host computer and run the +following command: + +.. code:: console + + $ avrdude -c stk500v2 -p m2560 -P /dev/ttyACM0 -U flash:w:nuttx.hex -v -D + +This command assumes that the board USB connection is available on ``ttyACM0``, +but you should verify the file path to its connection. You can use ``lsusb`` on +Linux to look for "Arduino SA Mega 2560 R3". + +If you want to reduce the console output of the command, remove the ``-v`` flag. + +The board uses the STK500v2 programmer type through the on-board programmer, +hence the argument to ``-c``. The argument to ``-p`` specifies the AVR device to +be the ATMega2560. The ``-U`` argument tells the program to write the +``nuttx.hex`` image to flash. + +Configurations +============== + +nsh +--- + +Very basic configuration with the ``nsh`` shell on the UART0 pins at a baud +rate of 38400. You can also access UART0 through the USB connector on your host +machine. diff --git a/boards/Kconfig b/boards/Kconfig index 2e21618780..64f394f707 100644 --- a/boards/Kconfig +++ b/boards/Kconfig @@ -27,6 +27,14 @@ config ARCH_BOARD_ARDUINO_MEGA2560 This option selects the Arduino Mega 2560 board featuring the Atmel Atmega2560 MCU running at 16 MHz. +config ARCH_BOARD_ELEGOO_MEGA2560R3 + bool "Elegoo Mega 2560r3" + depends on ARCH_CHIP_ATMEGA2560 + select ARCH_HAVE_LEDS + ---help--- + This option selects the Elegoo Mega 2560 board featuring the Atmel + Atmega2560 MCU running at 16 MHz. + config ARCH_BOARD_ARDUINO_DUE bool "Arduino Due" depends on ARCH_CHIP_ATSAM3X8E @@ -3450,6 +3458,7 @@ config ARCH_BOARD default "efm32-g8xx-stk" if ARCH_BOARD_EFM32G8XXSTK default "efm32gg-stk3700" if ARCH_BOARD_EFM32GG_STK3700 default "ekk-lm3s9b96" if ARCH_BOARD_EKKLM3S9B96 + default "elegoo-mega2560r3" if ARCH_BOARD_ELEGOO_MEGA2560R3 default "emw3162" if ARCH_BOARD_EMW3162 default "quickfeather" if ARCH_BOARD_QUICKFEATHER default "esp32-audio-kit" if ARCH_BOARD_ESP32_AUDIO_KIT @@ -4597,6 +4606,9 @@ endif if ARCH_BOARD_ARDUINO_MEGA2560 source "boards/avr/atmega/arduino-mega2560/Kconfig" endif +if ARCH_BOARD_ELEGOO_MEGA2560R3 +source "boards/avr/atmega/elegoo-mega2560r3/Kconfig" +endif if ARCH_BOARD_MOTEINO_MEGA source "boards/avr/atmega/moteino-mega/Kconfig" endif diff --git a/boards/avr/atmega/elegoo-mega2560r3/Kconfig b/boards/avr/atmega/elegoo-mega2560r3/Kconfig new file mode 100644 index 0000000000..ae2bf31307 --- /dev/null +++ b/boards/avr/atmega/elegoo-mega2560r3/Kconfig @@ -0,0 +1,4 @@ +# +# For a description of the syntax of this configuration file, +# see misc/tools/kconfig-language.txt. +# diff --git a/boards/avr/atmega/elegoo-mega2560r3/configs/nsh/defconfig b/boards/avr/atmega/elegoo-mega2560r3/configs/nsh/defconfig new file mode 100644 index 0000000000..2d690acf67 --- /dev/null +++ b/boards/avr/atmega/elegoo-mega2560r3/configs/nsh/defconfig @@ -0,0 +1,42 @@ +# +# This file is autogenerated: PLEASE DO NOT EDIT IT. +# +# You can use "make menuconfig" to make any modifications to the installed .config file. +# You can then do "make savedefconfig" to generate a new defconfig file that includes your +# modifications. +# +# CONFIG_DEBUG_OPT_UNUSED_SECTIONS is not set +CONFIG_ARCH="avr" +CONFIG_ARCH_AVR=y +CONFIG_ARCH_BOARD="elegoo-mega2560r3" +CONFIG_ARCH_BOARD_ELEGOO_MEGA2560R3=y +CONFIG_ARCH_CHIP="atmega" +CONFIG_ARCH_CHIP_ATMEGA2560=y +CONFIG_ARCH_CHIP_ATMEGA=y +CONFIG_ARCH_STACKDUMP=y +CONFIG_AVR_LINUXGCC_TOOLCHAIN=y +CONFIG_AVR_USART0=y +CONFIG_BOARD_LOOPSPERMSEC=800 +CONFIG_DEBUG_FULLOPT=y +CONFIG_DEBUG_SYMBOLS=y +CONFIG_DEFAULT_SMALL=y +CONFIG_DISABLE_MOUNTPOINT=y +CONFIG_IDLETHREAD_STACKSIZE=128 +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INIT_STACKSIZE=768 +CONFIG_INTELHEX_BINARY=y +CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=4 +CONFIG_NUNGET_CHARS=0 +CONFIG_POSIX_SPAWN_DEFAULT_STACKSIZE=768 +CONFIG_PTHREAD_STACK_DEFAULT=128 +CONFIG_PTHREAD_STACK_MIN=128 +CONFIG_RAM_SIZE=8192 +CONFIG_RAM_START=0x800200 +CONFIG_START_DAY=16 +CONFIG_START_MONTH=6 +CONFIG_START_YEAR=2011 +CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_SYSTEM_NSH=y +CONFIG_TASK_NAME_SIZE=0 +CONFIG_USART0_BAUD=38400 +CONFIG_USART0_SERIAL_CONSOLE=y diff --git a/boards/avr/atmega/elegoo-mega2560r3/include/board.h b/boards/avr/atmega/elegoo-mega2560r3/include/board.h new file mode 100644 index 0000000000..2912a8d263 --- /dev/null +++ b/boards/avr/atmega/elegoo-mega2560r3/include/board.h @@ -0,0 +1,88 @@ +/**************************************************************************** + * boards/avr/atmega/elegoo-mega2560r3/include/board.h + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __BOARDS_AVR_ATMEGA_ELEGOO_MEGA2560R3_INCLUDE_BOARD_H +#define __BOARDS_AVR_ATMEGA_ELEGOO_MEGA2560R3_INCLUDE_BOARD_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/* Configuration ************************************************************/ + +/* Clocking *****************************************************************/ + +/* Assume default CLKDIV8 fuse setting is overridden to CLKDIV1 */ + +/* #define BOARD_XTAL_FREQ 20000000 */ /* 20MHz crystal */ + +/* #define BOARD_XTAL_FREQ 16700000 */ /* 16.7MHz crystal */ + +#define BOARD_XTAL_FREQ 16000000 /* 16MHz crystal */ +#define BOARD_CPU_CLOCK BOARD_XTAL_FREQ /* F_CPU = 16MHz */ + +/* LED definitions for Elegoo Mega2560r3 */ + +#define LED_STARTED 0 /* OFF ON (when board turns on) */ +#define LED_HEAPALLOCATE 1 /* OFF ON (never happens) */ +#define LED_IRQSENABLED 1 /* OFF ON (never happens) */ +#define LED_STACKCREATED 1 /* ON ON (never happens) */ +#define LED_INIRQ 1 /* OFF NC (never happens) */ +#define LED_SIGNAL 1 /* OFF NC (never happens) */ +#define LED_ASSERTION 1 /* OFF NC (never happens) */ +#define LED_PANIC 2 /* OFF ON (1Hz flashing PB7) */ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +#ifndef __ASSEMBLY__ + +/**************************************************************************** + * Inline Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* __BOARDS_AVR_ATMEGA_ELEGOO_MEGA2560R3_INCLUDE_BOARD_H */ diff --git a/boards/avr/atmega/elegoo-mega2560r3/scripts/Make.defs b/boards/avr/atmega/elegoo-mega2560r3/scripts/Make.defs new file mode 100644 index 0000000000..be258e6210 --- /dev/null +++ b/boards/avr/atmega/elegoo-mega2560r3/scripts/Make.defs @@ -0,0 +1,37 @@ +############################################################################ +# boards/avr/atmega/elegoo-mega2560r3/scripts/Make.defs +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +include $(TOPDIR)/.config +include $(TOPDIR)/tools/Config.mk +include $(TOPDIR)/arch/avr/src/avr/Toolchain.defs + +LDSCRIPT = flash.ld +ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT) + + +CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) +CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) +CXXPICFLAGS = $(ARCHPICFLAGS) $(CXXFLAGS) +CPPFLAGS := $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) +AFLAGS := $(CFLAGS) -D__ASSEMBLY__ + +EXEEXT = .elf diff --git a/boards/avr/atmega/elegoo-mega2560r3/scripts/flash.ld b/boards/avr/atmega/elegoo-mega2560r3/scripts/flash.ld new file mode 100644 index 0000000000..b4e275f434 --- /dev/null +++ b/boards/avr/atmega/elegoo-mega2560r3/scripts/flash.ld @@ -0,0 +1,200 @@ +/**************************************************************************** + * boards/avr/atmega/elegoo-mega2560r3/scripts/flash.ld + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/* Memory Regions ***********************************************************/ + +/* ------ ------ ------+------- -- ------ -- ------ --- ------ ----+------- --- + * FLASH | REGISTERS I/O EXT I/O ISRAM | EEPROM + * | REGISTERS REGISTERS | + * ------- ------ -----+------- -- ------ -- ------ --- ------ ----+------- --- + * 0x0000 256Kb| 0x0000 32 0x0020 64 0x0060 416 0x0200 8Kb | 0x0000 4Kb + * ------- ------ -----+------- -- ------ -- ------ --- ------ ----+------- --- + * *Memory configuration A + */ + +MEMORY +{ + flash (rx) : ORIGIN = 0, LENGTH = 256K + sram (rw!x) : ORIGIN = 0x800200, LENGTH = 8K + eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = 4K +} + +ENTRY(__start) + +SECTIONS +{ + /* Read-only sections, merged into text segment: */ + + .hash : { *(.hash) } + .dynsym : { *(.dynsym) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .rel.init : { *(.rel.init) } + .rela.init : { *(.rela.init) } + + .rel.text : + { + *(.rel.text) + *(.rel.text.*) + *(.rel.gnu.linkonce.t*) + } + + .rela.text : + { + *(.rela.text) + *(.rela.text.*) + *(.rela.gnu.linkonce.t*) + } + + .rel.fini : { *(.rel.fini) } + .rela.fini : { *(.rela.fini) } + + .rel.rodata : + { + *(.rel.rodata) + *(.rel.rodata.*) + *(.rel.gnu.linkonce.r*) + } + + .rela.rodata : + { + *(.rela.rodata) + *(.rela.rodata.*) + *(.rela.gnu.linkonce.r*) + } + + .rel.data : + { + *(.rel.data) + *(.rel.data.*) + *(.rel.gnu.linkonce.d*) + } + + .rela.data : + { + *(.rela.data) + *(.rela.data.*) + *(.rela.gnu.linkonce.d*) + } + + .rel.ctors : { *(.rel.ctors) } + .rela.ctors : { *(.rela.ctors) } + .rel.dtors : { *(.rel.dtors) } + .rela.dtors : { *(.rela.dtors) } + .rel.got : { *(.rel.got) } + .rela.got : { *(.rela.got) } + .rel.bss : { *(.rel.bss) } + .rela.bss : { *(.rela.bss) } + .rel.plt : { *(.rel.plt) } + .rela.plt : { *(.rela.plt) } + + .text : + { + _stext = . ; + KEEP(*(.vectors)) + *(.init) + *(.handlers) + *(.progmem .progmem.*) + . = ALIGN(2); + *(.text) + *(.text.*) + _etext = . ; + } > flash + + .data : + { + _sdata = ABSOLUTE(.); + *(.rodata .rodata.*) + *(.data .data.*) + *(.gnu.linkonce.d.*) + CONSTRUCTORS + _edata = ABSOLUTE(.); + } > sram AT > flash + + _eronly = LOADADDR(.data); + + .bss : + { + _sbss = ABSOLUTE(.); + *(.bss .bss.*) + *(.gnu.linkonce.b.*) + *(COMMON) + _ebss = ABSOLUTE(.); + } > sram + + /* Global data not cleared after reset. */ + + .noinit : + { + _snoinit = ABSOLUTE(.); + *(.noinit*) + _enoinit = ABSOLUTE(.); + } > sram + + .eeprom : + { + _seeprom = ABSOLUTE(.); + *(.eeprom*) + _eeeprom = ABSOLUTE(.); + } > eeprom + + /* Stabs debugging sections. */ + + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 : { *(.comment) } + + /* DWARF debug sections. + Symbols in the DWARF debugging sections are relative to the beginning + of the section so we begin them at 0. */ + + /* DWARF 1 */ + + .debug 0 : { *(.debug) } + .line 0 : { *(.line) } + + /* GNU DWARF 1 extensions */ + + .debug_srcinfo 0 : { *(.debug_srcinfo) } + .debug_sfnames 0 : { *(.debug_sfnames) } + + /* DWARF 1.1 and DWARF 2 */ + + .debug_aranges 0 : { *(.debug_aranges) } + .debug_pubnames 0 : { *(.debug_pubnames) } + + /* DWARF 2 */ + + .debug_info 0 : { *(.debug_info) *(.gnu.linkonce.wi.*) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_line 0 : { *(.debug_line) } + .debug_frame 0 : { *(.debug_frame) } + .debug_str 0 : { *(.debug_str) } + .debug_loc 0 : { *(.debug_loc) } + .debug_macinfo 0 : { *(.debug_macinfo) } +} diff --git a/boards/avr/atmega/elegoo-mega2560r3/src/Makefile b/boards/avr/atmega/elegoo-mega2560r3/src/Makefile new file mode 100644 index 0000000000..de15084f89 --- /dev/null +++ b/boards/avr/atmega/elegoo-mega2560r3/src/Makefile @@ -0,0 +1,31 @@ +############################################################################ +# boards/avr/atmega/elegoo-mega2560r3/src/Makefile +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +include $(TOPDIR)/Make.defs + +CSRCS = avr_boot.c + +ifeq ($(CONFIG_ARCH_LEDS),y) +CSRCS += avr_leds.c +endif + +include $(TOPDIR)/boards/Board.mk diff --git a/boards/avr/atmega/elegoo-mega2560r3/src/avr_boot.c b/boards/avr/atmega/elegoo-mega2560r3/src/avr_boot.c new file mode 100644 index 0000000000..bbd2977b33 --- /dev/null +++ b/boards/avr/atmega/elegoo-mega2560r3/src/avr_boot.c @@ -0,0 +1,68 @@ +/**************************************************************************** + * boards/avr/atmega/elegoo-mega2560r3/src/avr_boot.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <debug.h> + +#include <arch/board/board.h> +#include <nuttx/board.h> + +#include "atmega.h" +#include "avr_internal.h" +#include "elegoo_mega2560r3.h" + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: up_boardinitialize + * + * Description: + * All ATMega architectures must provide the following entry point. + * This entry point is called early in the initialization -- after all + * memory has been configured and mapped but before any devices have been + * initialized. + * + ****************************************************************************/ + +void atmega_boardinitialize(void) +{ + /* Configure on-board LEDs if LED support has been selected. */ + +#ifdef CONFIG_ARCH_LEDS + board_autoled_initialize(); +#endif +} diff --git a/boards/avr/atmega/elegoo-mega2560r3/src/avr_leds.c b/boards/avr/atmega/elegoo-mega2560r3/src/avr_leds.c new file mode 100644 index 0000000000..84cbc771cc --- /dev/null +++ b/boards/avr/atmega/elegoo-mega2560r3/src/avr_leds.c @@ -0,0 +1,81 @@ +/**************************************************************************** + * boards/avr/atmega/elegoo-mega2560r3/src/avr_leds.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <debug.h> + +#include <arch/board/board.h> +#include <avr/io.h> + +#include "avr_internal.h" +#include "elegoo_mega2560r3.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_autoled_initialize + ****************************************************************************/ + +#ifdef CONFIG_ARCH_LEDS +void board_autoled_initialize(void) +{ + DDRB |= (1 << 7); /* Configure as output */ +} + +/**************************************************************************** + * Name: board_autoled_on + ****************************************************************************/ + +void board_autoled_on(int led) +{ + switch (led) + { + case LED_STARTED: + case LED_PANIC: + PORTB |= (1 << 7); + break; + } +} + +/**************************************************************************** + * Name: board_autoled_off + ****************************************************************************/ + +void board_autoled_off(int led) +{ + switch (led) + { + case LED_STARTED: + case LED_PANIC: + PORTB &= ~(1 << 7); + break; + } +} + +#endif /* CONFIG_ARCH_LEDS */ diff --git a/boards/avr/atmega/elegoo-mega2560r3/src/elegoo_mega2560r3.h b/boards/avr/atmega/elegoo-mega2560r3/src/elegoo_mega2560r3.h new file mode 100644 index 0000000000..bc6c021ad6 --- /dev/null +++ b/boards/avr/atmega/elegoo-mega2560r3/src/elegoo_mega2560r3.h @@ -0,0 +1,53 @@ +/**************************************************************************** + * boards/avr/atmega/elegoo-mega2560r3/src/elegoo_mega2560r3.h + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __BOARDS_AVR_ATMEGA_ELEGOO_MEGA2560R3_SRC_ELEGOO_MEGA2560R3_H +#define __BOARDS_AVR_ATMEGA_ELEGOO_MEGA2560R3_SRC_ELEGOO_MEGA2560R3_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/* Configuration ************************************************************/ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +#ifndef __ASSEMBLY__ + +/**************************************************************************** + * Inline Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#endif /* __ASSEMBLY__ */ +#endif /* __BOARDS_AVR_ATMEGA_ELEGOO_MEGA2560R3_SRC_ELEGOO_MEGA2560R3_H */