RIOT-OS / RIOT

RIOT - The friendly OS for IoT
https://riot-os.org
GNU Lesser General Public License v2.1
4.94k stars 1.99k forks source link

board:cpu: RIOT port for the atsamr21xpro board #1646

Closed thomaseichinger closed 7 years ago

thomaseichinger commented 10 years ago

List to coordinate porting efforts for the samr21xpro board and it's samd21 cpu. Please leave a comment what you are working on to mark it in the list and open pull requests against https://github.com/thomaseichinger/RIOT/tree/samr21 master branch.

Porting todos:

N8Fear commented 10 years ago

Sorry - I should really look where I'm clicking at... :-/

Troels51 commented 10 years ago

Hey, i'm new to this project but i'm looking into porting RIOT to the board as well. I've been working on gpio and timers

thomaseichinger commented 10 years ago

@Troels51, welcome! Great to hear, I marked GPIO in the list with your name.

wiredsource commented 10 years ago

@thomaseichinger Troels and myself are two of the tree students from Aarhus University. e.g. "[riot-devel] RIOT OS for the Atmel SAM R21 (ARM m0+)" thread

thomaseichinger commented 10 years ago

@wiredsource welcome to you too! Are you working on GPIO too?

To give a short update regarding UART, I've some output right now but it is still invalid. Also watch out when configuring GCLK modules, if misconfigured the board isn't reachable anymore via open-ocd and has to be erased using AtmelStudio (AFAIK Windows only).

wiredsource commented 10 years ago

@thomaseichinger Right now i'm just spectating because i need a better overview over the system. @Troels51 has worked with it for the past week so he has a way better understanding of the architecture.

I will start on something constructive soon :-)

wiredsource commented 10 years ago

Hi @thomaseichinger I hope you had a good weekend...?

I have a question... What is the status on the UART? We are very excited to know about this one for debugging purposes. @Troels51 have worked on the timers for the last few days and also went around the UART a bit.

But do you have an idea of when it could be ready for test?

thomaseichinger commented 10 years ago

Currently I've output from the UART but it is scrambled, I'll have to tweak some parameters regarding clk settings and baudrate. Hope to get it done by tomorrow.

wiredsource commented 10 years ago

Very good news :+1:

I looked at your uart file earlier and i spotted that you used a baudrate 115200 right? I'm pretty sure the default is 9600. But if theres a problem with the clk it's properly around that one the issue remains...?

wiredsource commented 10 years ago

@thomaseichinger

I'm trying my luck with the ADC atm :-D

thomaseichinger commented 10 years ago

I pushed my latest changes to my repository. It's still not working correctly but I can't see the error right now. Maybe a couple of fresh eyes can spot it.

@wiredsource great, I marked the list entry.

wiredsource commented 10 years ago

@thomaseichinger

Cool we'll check it out right way.

Regarding the ADC...

Would it be possible to perhaps make an ADC extension feature of these configurations? Did this issue not come up with some of the other ADC types?

Any suggestions?

thomaseichinger commented 10 years ago

The basic idea of periph/* drivers is to provide a subset of functionality that is common to all platforms in the best case. This said there is the possibility to implement more advanced features this for this board only besides these interfaces. If it is a matter of configuration, meaning adding a parameter to the initialisation I'd propose you open a PR against periph/adc.hwith suggestions so this could be discussed in more detail.

Troels51 commented 10 years ago

The UART is working for me right now, i think the clocks were set up in a faulty way.

OlegHahm commented 10 years ago

Sounds awesome - can you send a pointer to your version with working UART?

Troels51 commented 10 years ago

@OlegHahm Here it is https://github.com/Troels51/RIOT/tree/samr21

wiredsource commented 10 years ago

@thomaseichinger @OlegHahm

Hi guys!

i'm getting an error while flashing the chip: make BOARD=atsamr21-xpro flash

Building application default for atsamr21-xpro w/ MCU samd21. "make" -C /home/stud/BeeGit/RIOT/cpu/samd21 "make" -C /home/stud/BeeGit/RIOT/cpu/samd21/periph "make" -C /home/stud/BeeGit/RIOT/cpu/cortex-m0_common "make" -C /home/stud/BeeGit/RIOT/boards/atsamr21-xpro "make" -C /home/stud/BeeGit/RIOT/core "make" -C /home/stud/BeeGit/RIOT/drivers "make" -C /home/stud/BeeGit/RIOT/sys "make" -C /home/stud/BeeGit/RIOT/sys/auto_init "make" -C /home/stud/BeeGit/RIOT/sys/lib "make" -C /home/stud/BeeGit/RIOT/sys/ps "make" -C /home/stud/BeeGit/RIOT/sys/posix "make" -C /home/stud/BeeGit/RIOT/sys/shell "make" -C /home/stud/BeeGit/RIOT/sys/shell/commands "make" -C /home/stud/BeeGit/RIOT/sys/timex "make" -C /home/stud/BeeGit/RIOT/sys/uart0 "make" -C /home/stud/BeeGit/RIOT/sys/vtimer text data bss dec hex filename 48732 2260 16748 67740 1089c /home/stud/BeeGit/RIOT/examples/adc_default/bin/atsamr21-xpro/default.elf /home/stud/BeeGit/RIOT/boards/atsamr21-xpro/dist/flash.sh /home/stud/BeeGit/RIOT/examples/adc_default/bin/atsamr21-xpro/default.hex Open On-Chip Debugger 0.9.0-dev-00148-g3a4ec66 (2014-09-19-10:22) Licensed under GNU GPL v2 For bug reports, read http://openocd.sourceforge.net/doc/doxygen/bugs.html Error: The specified debug interface was not found (cmsis-dap) The following debug interfaces are available: Runtime Error: /usr/local/share/openocd/scripts/interface/cmsis-dap.cfg:7: in procedure 'script' at file "embedded:startup.tcl", line 58 at file "/usr/local/share/openocd/scripts/board/atmel_samr21_xplained_pro.cfg", line 5 in procedure 'interface' called at file "/usr/local/share/openocd/scripts/interface/cmsis-dap.cfg", line 7 make: *\ [flash] Error 1

:-(

Do you know how i can fix this???

LudwigKnuepfer commented 10 years ago

@thomaseichinger Maybe it makes sense to include the correctly configured version of openocd in dist?

wiredsource commented 10 years ago

FIXED! This was the problem: No HIDAPI & LIBUDEV

then setting up openocd: ./configure --enable-maintainer-mode --enable-cmsis-dap --enable-hidapi-libusb

ref. http://karibe.co.ke/2013/08/setting-up-linux-opensource-build-and-debug-tools-for-freescale-freedom-board-frdm-kl25z/

wiredsource commented 10 years ago

@thomaseichinger

I got a working ADC now...

TODOs:

wiredsource commented 10 years ago

well now i've got an new error after disconnecting my device and reattached it....

Open On-Chip Debugger 0.9.0-dev-00148-g3a4ec66 (2014-09-19-12:50) Licensed under GNU GPL v2 For bug reports, read http://openocd.sourceforge.net/doc/doxygen/bugs.html Info : only one transport option; autoselect 'cmsis-dap' adapter speed: 500 kHz adapter_nsrst_delay: 100 cortex_m reset_config sysresetreq Error: unable to open CMSIS-DAP device in procedure 'init' make: *\ [flash] Error 1

------------------------------> Google is not my friend on this one...

I'm running vmware kubuntu 14.04 ( i know)

I have tried disconnecting/reconnecting it in vmware.

erased the device in atmel studio

dmesg: [ 924.369050] usb 1-1: USB disconnect, device number 2 [ 1485.569981] usb 1-1: new high-speed USB device number 7 using ehci-pci [ 1485.778852] usb 1-1: config 1 interface 2 altsetting 0 bulk endpoint 0x84 has invalid maxpacket 64 [ 1485.778858] usb 1-1: config 1 interface 2 altsetting 0 bulk endpoint 0x5 has invalid maxpacket 64 [ 1485.786816] usb 1-1: New USB device found, idVendor=03eb, idProduct=2111 [ 1485.786821] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [ 1485.786824] usb 1-1: Product: EDBG CMSIS-DAP [ 1485.786826] usb 1-1: Manufacturer: Atmel Corp. [ 1485.786828] usb 1-1: SerialNumber: ATML2127031800003561 [ 1485.812279] hid-generic 0003:03EB:2111.0004: hiddev0,hidraw0: USB HID v1.11 Device [Atmel Corp. EDBG CMSIS-DAP] on usb-0000:02:03.0-1/input0 [ 1485.812617] cdc_acm 1-1:1.1: ttyACM0: USB ACM device [ 1485.937851] usb 1-2: new high-speed USB device number 8 using ehci-pci [ 1486.166388] usb 1-2: device descriptor read/64, error 18 [ 1486.503139] usb 1-2: device descriptor read/64, error 18 [ 1486.830552] usb 1-2: new high-speed USB device number 9 using ehci-pci [ 1487.060365] usb 1-2: device descriptor read/64, error 18 [ 1487.391442] usb 1-2: device descriptor read/64, error 18 [ 1487.723890] usb 1-2: new high-speed USB device number 10 using ehci-pci [ 1487.744562] usb 1-2: Invalid ep0 maxpacket: 9 [ 1487.972014] usb 1-2: new high-speed USB device number 11 using ehci-pci [ 1487.992518] usb 1-2: Invalid ep0 maxpacket: 9 [ 1487.996130] hub 1-0:1.0: unable to enumerate USB device on port 2

i spotted the "unable to enumerate USB device on port 2" but it should not the the port the debuggers running...?

wiredsource commented 10 years ago

OK sudo make BOARD=atsamr21-xpro flash

sudo did it...

N8Fear commented 10 years ago

I'd rather change permissions on the device or what ever else needs it. sudo and make IMHO aren't that great a combination...

LudwigKnuepfer commented 10 years ago

Maybe it would also be a good idea to document how to properly change the device permissions in the wiki.

wiredsource commented 10 years ago

fixed the permissions with the same link above... http://karibe.co.ke/2013/08/setting-up-linux-opensource-build-and-debug-tools-for-freescale-freedom-board-frdm-kl25z/

remember to unplug/replug the device before testing it

wiredsource commented 10 years ago

Hi again guys

Sorry to bother you all the time...

I'm experiencing a slight odd behavior from the CMSIS-DAP. It says it wrote some bytes but the board seems to be in a limbo state or something because it becomes inaccessible right after flash.

Open On-Chip Debugger 0.9.0-dev-00148-g3a4ec66 (2014-09-19-12:50) Licensed under GNU GPL v2 For bug reports, read http://openocd.sourceforge.net/doc/doxygen/bugs.html Info : only one transport option; autoselect 'cmsis-dap' adapter speed: 500 kHz adapter_nsrst_delay: 100 cortex_m reset_config sysresetreq Info : CMSIS-DAP: SWD Supported Info : CMSIS-DAP: Interface Initialised (SWD) Info : CMSIS-DAP: FW Version = 01.1B.00FC Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 0 nRESET = 1 Info : DAP_SWJ Sequence (reset: 50+ '1' followed by 0) Info : CMSIS-DAP: Interface ready Info : clock speed 500 kHz Info : IDCODE 0x0bc11477 Info : at91samr21g18.cpu: hardware has 4 breakpoints, 2 watchpoints TargetName Type Endian TapName State


0* at91samr21g18.cpu cortex_m little at91samr21g18.cpu running target state: halted target halted due to debug-request, current mode: Thread xPSR: 0x61000000 pc: 0x000002d4 msp: 0x20004a40 target state: halted target halted due to debug-request, current mode: Thread xPSR: 0x61000000 pc: 0x000002d4 msp: 0x20004a40 auto erase enabled Info : SAMD MCU: SAMR21G18A (256KB Flash, 32KB RAM) wrote 65536 bytes from file /home/stud/BeeGit/RIOT/examples/adc_default/bin/atsamr21-xpro/default.hex in 62.818192s (1.019 KiB/s) verified 51264 bytes in 4.311374s (11.612 KiB/s) shutdown command invoked

^^ Is it normal to print out Target state: halted?

And i would say that the size of 51kb is very large...? @Troels51 his build is only 15-16kb...

thomaseichinger commented 10 years ago

@all Awesome work you did! @Troels51 I'll merge your PR and will prepare a PR against the main repo for Monday together with my basic timer implementation. @wiredsource maybe you could also open a PR for the ADC module?

Regarding the binary size, check which optimisation flag you define in atsamr21-pro/Makefile.include in the CFLAGS section. I once changed it to -O0 for debugging purposes. You could change this to -Os if applicable and check the size again.

The target state is always haltet for flashing and also after entering gdb. What do you mean by inaccessible? Do you mean openocd access?

Regarding fixing permissions for openocd access, it would be great if someone with a Linux machine who already successfully fixed this could document it in the wiki, maybe in a separate "openocd" page? We then could link against this in the documentation of the boards openocd is used for.

LudwigKnuepfer commented 10 years ago

only to make sure openocd isn't forgotten: https://github.com/RIOT-OS/RIOT/issues/1690

thomaseichinger commented 10 years ago

I pushed the basic timer implementation yesterday.

@Troels51 I'm currently reworking your GPIO implementation to get it work with external interrupts and clean it up.

When this is done I'll open a PR against RIOT's main repo. @haukepetersen and me agreed to put this on the fast lane then to get a more central synchronisation point. E.g. the initial import will be probably buggy and not as clean as other implementations but it should make distributed development much easier.

wiredsource commented 10 years ago

@thomaseichinger Is anybody onto the RTC yet? I made the ADC PR so i will try wrestle a little bit with RTC then... ok?

thomaseichinger commented 10 years ago

@wiredsource The RTC is yours! Regarding the ADC, awesome, please mind the comment on the PR.

wiredsource commented 10 years ago

THX for The heads up! I'll go read a bit ;-) ATM I'm back on the ADC for some refactoring.

Sent from Yahoo Mail on Android

thomaseichinger commented 10 years ago

The initial import for the samr21-xpro got merged recently thus I'll close this issue. I added a table to reflect the implementation status to the wiki. All future PRs should be made against RIOT's main repo.

wiredsource commented 9 years ago

@thomaseichinger we have got a wokring CPUID implementation.

biboc commented 9 years ago

@haukepetersen , should you update the Implementation Status in the wiki as well?

thomaseichinger commented 9 years ago

@wiredsource I marked cpuid as yours (mind opening a PR?) @bapclenet I updated the wiki

Troels51 commented 9 years ago

@thomaseichinger The cpuid PR is sent

haukepetersen commented 9 years ago

I am out. Won't get to the PWM anytime soon...

biboc commented 9 years ago

I've got some questions about the implementation:

biboc commented 9 years ago

I'm working on RNG implementation. It will use the at86rf231 random number.

biboc commented 9 years ago

@Wiredsource, I don't know if you're still working on the RTC but I've got one almost finished (just need to deal with the alarm and callback) I will do a pull request as soon ass my I2C PR is merged.

wiredsource commented 9 years ago

@bapclenet I'm not working on that atm. My work goes to my exam project now. So if you got something that would be cool! We have tried something out regarding powersave mode and are testing it today.

btw. do you have an SHT21 driver for RIOT? ;-) it have been a pain for far too long ... And i simply can't figure it out. I'm sure it is a minor one but where...? :-D

wiredsource commented 9 years ago

@thomaseichinger

We made some powersaving tweaks on the transceiver by using some of the features within the AT86RF233 hardware...

By now we managed a current consumption drop by 30%+

biboc commented 9 years ago

I don't have a SHT21 driver, sorry. Use my I2C driver (https://github.com/RIOT-OS/RIOT/pull/2016) and it should work.

That's very great for powersaving! Where can I see your progress?

biboc commented 9 years ago

RTC done, will do my PR after I2C merged.

thomaseichinger commented 9 years ago

@wiredsource Awesome, let's target a consolidation of the at86rf2xx driver for the beginning of next year. @bapclenet i2c got merged, looking forward for your upcoming contributions.

wiredsource commented 9 years ago

@bapclenet

you can find it in this messy one within the function int at86rf231_on(void): https://github.com/wiredsource/RIOT/tree/beehive

The transceiver gonna take use of the RPC features only found in the 233 version. You have to know that we have been trying to get the most out of these features therefore it properly going to get a lower performance... We have not tested the impact of these features yet! Only a few meters in between router and node... A real life test of transmit distance most be tried at some point...

LudwigKnuepfer commented 9 years ago

reopening as it's still in use

saurabh984 commented 9 years ago

Any one fancy trying the LPM code for me please?? Literally wrote this on Github's editor on my iPad so can't test it :disappointed:

/*
 * Copyright (C) 2014 Freie Universität Berlin
 *
 * This file is subject to the terms and conditions of the GNU Lesser
 * General Public License v2.1. See the file LICENSE in the top level
 * directory for more details.
 */

/**
 * @ingroup     cpu_samd21
 * @{
 *
 * @file        lpm_arch.c
 * @brief       Implementation of the kernels power management interface
 * 
 * @author      Thomas Eichinger <thomas.eichinger@fu-berlin.de>
 *
 * @}
 */
#include "cpu.h"
#include "arch/lpm_arch.h"

enum system_sleepmode {
    /**
     *  Idle 0 mode.
     *  Potential Wake Up sources: Synchronous(APB, AHB), asynchronous.
     */
    SYSTEM_SLEEPMODE_IDLE_0,
    /**
     *  Idle 1 mode.
     *  Potential Wake Up sources: Synchronous (APB), asynchronous
     */
    SYSTEM_SLEEPMODE_IDLE_1,
    /**
     *  Idle 2 mode.
     *  Potential Wake Up sources: Asynchronous
     */
    SYSTEM_SLEEPMODE_IDLE_2,
    /**
     * Standby mode.
     * Potential Wake Up sources: Asynchronous
     */
    SYSTEM_SLEEPMODE_STANDBY,
};

static enum lpm_mode current_mode;

void lpm_arch_init(void)
{
    current_mode = LPM_ON;
}

enum lpm_mode lpm_arch_set(enum lpm_mode target)
{
enum lpm_mode last_mode = current_mode;

    switch (target) {
        case LPM_ON:                    /* Run mode */
            current_mode = LPM_ON;
            break;
        case LPM_IDLE:                  /* Sleep mode Idle 0 */
            current_mode = LPM_IDLE;
            /* Idle Mode 0 */
            SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
            PM->SLEEP.reg = SYSTEM_SLEEPMODE_IDLE_0;
            start_lpm();
            break;
        case LPM_SLEEP:                 /* Sleep mode Idle 1 */
            current_mode = LPM_SLEEP;
             /* Idle Mode 1 */
            SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
            PM->SLEEP.reg = SYSTEM_SLEEPMODE_IDLE_1;
            start_lpm();
            break;
        case LPM_POWERDOWN:             /* Sleep mode Idle 2 */
            /* Idle Mode 2 */
            SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
            PM->SLEEP.reg = SYSTEM_SLEEPMODE_IDLE_2;
            start_lpm();
            break;
        case LPM_OFF:                   /* Standby Mode - Potential Wake Up sources: Asynchronous */
            current_mode = LPM_POWERDOWN;
            /* Standby Mode */
            SCB->SCR |=  SCB_SCR_SLEEPDEEP_Msk;
            start_lpm();
            break;
        default:
            break;
    }

    return last_mode;
}

static void start_lpm(void) 
{
    /* Executes a device DSB (Data Synchronization Barrier) */
    __DSB();
    /* Enter standby mode */
    __WFI();
}

enum lpm_mode lpm_arch_get(void)
{
    return current_mode;
}

void lpm_arch_awake(void)
{
    if (current_mode == LPM_SLEEP) {
        /* Re-init */
        cpu_init();
    }
    current_mode = LPM_ON;
}

/** Not needed */
void lpm_arch_begin_awake(void){ }

/** Not needed */
void lpm_arch_end_awake(void){ }
LudwigKnuepfer commented 9 years ago

Compiles after adding static void start_lpm(void); at the top ;)