RIOT on new board (atmega1284p)

Hi guys,

Maybe someone can help me. I have the task to implement RIOT on this MC: AVR-based Sensor Node with Xbee (ASN(x)) → https://github.com/DoWiD-wsn/avr-based_sensor_node.

Its an ATmega1284p MCU with a different PCB (findable in git under /docs/pcb_design.md)

I am currently doing the steps from (doc.riot-os) porting-boards.html and trying to do the board definitions.

I know I can integrate the header files in a own folder and have to edit the Makefile.include: INCLUDES += -I<some>/<directory>/<path>. But where can I place the source files from https://github.com/DoWiD-wsn/avr-based_sensor_node/tree/master/source/asnx_lib ? (for example: the uart file which is placed in /uart/uart.c)

Can you also give me a few tips to run RIOT on this avr-based_sensor_node in general?

I would appreciate your support!

Hi,

One thing is to port the OS to a new architecture, and other thing is to create a BSP (board support package) for that new architecture.

First make the new port work (to compile and to run single tasks inside a minimal system). Start with a known and similar port, like the one for the ATMEGA328 (core is identical among Atmel devices). Once you’ve done it, then move on into the BSP.

I guess a better starting point would be boards/mega-xplained or just the plain boards/atmega1284p board.

The CPU is already supported by RIOT, you only have to provide a board definition.

You can start by copying one of the existing boards and make adjustments to match your hardware.

Thank you for your input.

What I did in the meantime: (I): I have created a new board by copy the folder /RIOT/boards/atmega1284p to a new folder named /RIOT/boards/myboard2021_2

(II): I have also created a new module with “make generate-module” (which creates a new module in RIOT/sys/) named “myboard2021_hw” and “led”, and have copied the 2 *.c files from https://github.com/DoWiD-wsn/avr-based_sensor_node/tree/master/source/asnx_lib/hw into it.

(III): I added into “Makefile.dep” of RIOT/boards/myboards2021_2 this: USEMODULE += boards_common_atmega USEMODULE += myboard2021_hw USEMODULE += led USEMODULE += xtimer

and added into RIOT/boards/myboards2021_2/includes the 2 header files “hw.h” and “led.h”.

(IV): I have created a application file/directory with this main.c:

and this applciation Makefile:

grafik

and flashed it with:

sudo BOARD=myboard2021_2 AVRDUDE_PROGRAMMER=stk500v2 PORT=/dev/ttyACM0 make all flash

OUTPUT: Blinky was working corretly! :slight_smile:

But UART is still not working :frowning:

I tried to run: sudo BOARD=myboard2021_2 AVRDUDE_PROGRAMMER=stk500v2 PORT=/dev/ttyUSB0 make term

but the output is always:

/home/user/Tutorials/RIOT/dist/tools/pyterm/pyterm -p “/dev/ttyUSB0” -b “9600” Twisted not available, please install it if you want to use pyterm’s JSON capabilities 2021-12-03 16:48:26,338 # Connect to serial port /dev/ttyUSB0 Welcome to pyterm! Type ‘/exit’ to exit.

No output and input via UART possible. Do you know how to change the UART dev from “UART 0” to “UART 1”?

I tried also to include the UART files from https://github.com/DoWiD-wsn/avr-based_sensor_node/tree/master/source/asnx_lib/uart to a new module like discribed in (II) but it did not work. → and I also think that RIOT has a own uart and printf function!?

Do you have any idea how to run UART on UART1 on atmega1284p?

did you try some other example like examples/hello-world or examples/default?

Mind you that in the code you posted you have the LED blinking in an infinite loop, so the code that will start the shell is never reached.

RIOT has it’s own HAL (see cpu/atmega_common/periph) so you don’t need to pull in any third party files for UART support.

I tried it with both examples " examples/hello-world" and " examples/default". I was able to flash both examples on the board, but UART does not work.

I also removed the loop in my code, still the same issue → UART does not work

With the native board it works:

user@riot-vm:~/Tutorials/RIOT/examples/hello-world$ sudo make term
/home/user/Tutorials/RIOT/examples/hello-world/bin/native/hello-world.elf /dev/ttyACM0
RIOT native interrupts/signals initialized.
LED_RED_OFF
LED_GREEN_ON
RIOT native board initialized.
RIOT native hardware initialization complete.

main(): This is RIOT! (Version: 2021.01)
Hello World!
You are running RIOT on a(n) native board.
This board features a(n) native MCU.

It seems like the UART config isnt correct in my case. I will double check it. Do you have any idea why it doesnt work?

just for info: uart1 is using register/port UCSR1A on my board

Ah sorry, I did not read that. You can do so with

#define STDIO_UART_DEV      UART_DEV(1)

in your board.h

good news :slight_smile:

I have to start the serial connection first with /dev/ttyUSB0 (terminal 2 (terminal on the right side)) and after that I flashed the “hello world” main.c with “sudo BOARD=myboard2021_2 AVRDUDE_PROGRAMMER=stk500v2 PORT=/dev/ttyACM0 make all flash”

Thank you very much for your help so far!

I will try now to implement the sensors like in: https://github.com/DoWiD-wsn/avr-based_sensor_node/tree/master/source/002-sensor_demo

it seems like only UART “read” mode works.

on the left side of the screenshot you can see the “native” Uart communication, and on the right side “myboard” UART:

“hello” and “board_say_thanks” commands on the command line in UART do not work. Seems like a missing config for UART write communication. any ideas?

main.c:

user@riot-vm:~/Tutorials/task-01$ cat main.c #include <stdio.h> #include <string.h> #include “shell.h” #include <unistd.h>

static int hello_world(int argc, char **argv) {
            /* Suppress compiler errors */
            (void)argc;
                (void)argv;
                    printf("hello world!\n");
                        return 0;
}

static int say_thanks(int argc, char **argv) {
                    /* Suppress compiler errors */
                    (void)argc;
                                    (void)argv;
                                                        printf("Thank you RIOT community!\n");
                                                                                return 0;
}

const shell_command_t shell_commands[] = {
            {"hello", "prints hello world", hello_world},
            {"board_say_thanks", "prints thank you", say_thanks},
            { NULL, NULL, NULL }
};

int main(void)
{
                        char line_buf[SHELL_DEFAULT_BUFSIZE];
                shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
}

Looks like you aren’t getting any RX interrupt. Can you post you board configuration? Your RIOT version seems a bit old, maybe check with the latest master first.

btw: You probably noticed that a some of those sensors already have drivers in RIOT so you can just e.g. USEMODULE += lm75a to add the driver to your application.

funny thing! I dont know why, but it works now.

I did 3 things: (I) check the latest RIOT version (Version: 2022.01-devel-991-g9c5391) (II) reinstalled my virtuell OS (III) changed the value of “#define CLOCK_CORECLOCK” in RIOT/boards/myboard2021_2/include/periph_conf.h from “(8000000UL)” to “(4000000UL)” -----> #define CLOCK_CORECLOCK (4000000UL) (I am not sure I did that before)

@regarding the RIOT drivers, thanks for the tip. I will try that in the next step.