Skip to content

Commit beb2ef1

Browse files
soc: atmel_sam0: Add support for SAMR34 and SAMR35 parts
Implement support for SAMR34 and SAMR35 parts, tested on a SAMR34 Xplained Pro dev board. Confirmed operational peripherals: UART, GPIO, PWM, ADC. NOTE: The SAMR34 datasheet lists NVIC line 20 for the ADC's interrupt, but the SAML21 datasheet gives line 22. It appears that the SAMR34 sheet is incorrect (the ADC doesn't function with line 20), and as such, I have also omitted the adjustments for TC4 and AC... Signed-off-by: Attie Grande <[email protected]>
1 parent 44f9df0 commit beb2ef1

File tree

15 files changed

+349
-2
lines changed

15 files changed

+349
-2
lines changed

dts/arm/atmel/samr34.dtsi

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) 2021 Argentum Systems Ltd.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <freq.h>
8+
#include <atmel/saml21.dtsi>
9+
#include <dt-bindings/lora/sx126x.h>
10+
11+
#include "saml21.dtsi"
12+
13+
/ {
14+
aliases {
15+
lora0 = &lora;
16+
};
17+
18+
soc {
19+
pinctrl@40002800 {
20+
ranges = <0x40002800 0x40002800 0x180>;
21+
22+
portc: gpio@40002900 {
23+
compatible = "atmel,sam0-gpio";
24+
reg = <0x40002900 0x80>;
25+
label = "PORTC";
26+
gpio-controller;
27+
#gpio-cells = <2>;
28+
#atmel,pin-cells = <2>;
29+
};
30+
};
31+
};
32+
};
33+
34+
/delete-node/ &dac;
35+
36+
&sercom4 {
37+
/* SERCOM4 is used to interface with the internal LoRa radio */
38+
compatible = "atmel,sam0-spi";
39+
dipo = <0>;
40+
dopo = <1>;
41+
cs-gpios = <&portb 31 GPIO_ACTIVE_LOW>;
42+
#address-cells = <1>;
43+
#size-cells = <0>;
44+
45+
lora: sx1276@0 {
46+
compatible = "semtech,sx1276";
47+
reg = <0>;
48+
label = "SX1276";
49+
reset-gpios = <&portb 15 GPIO_ACTIVE_LOW>; /* nRST */
50+
dio-gpios =
51+
<&portb 16 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>, /* DIO0 */
52+
<&porta 11 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>, /* DIO1 */
53+
<&porta 12 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>, /* DIO2 */
54+
<&portb 17 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>, /* DIO3 */
55+
<&porta 10 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>, /* DIO4 */
56+
<&portb 0 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>; /* DIO5 */
57+
spi-max-frequency = <DT_FREQ_M(10)>;
58+
};
59+
};

dts/arm/atmel/samr35.dtsi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Copyright (c) 2021 Argentum Systems Ltd.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <atmel/samr34.dtsi>
8+
9+
/delete-node/ &usb0;

soc/arm/atmel_sam0/common/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ zephyr_sources_ifdef(CONFIG_SOC_SERIES_SAMD20 soc_samd2x.c)
1111
zephyr_sources_ifdef(CONFIG_SOC_SERIES_SAMD21 soc_samd2x.c)
1212
zephyr_sources_ifdef(CONFIG_SOC_SERIES_SAMR21 soc_samd2x.c)
1313
zephyr_sources_ifdef(CONFIG_SOC_SERIES_SAML21 soc_saml2x.c)
14+
zephyr_sources_ifdef(CONFIG_SOC_SERIES_SAMR34 soc_saml2x.c soc_samr34.c)
15+
zephyr_sources_ifdef(CONFIG_SOC_SERIES_SAMR35 soc_saml2x.c soc_samr34.c)
1416

1517
zephyr_sources_ifdef(CONFIG_SOC_SERIES_SAMD51 soc_samd5x.c)
1618
zephyr_sources_ifdef(CONFIG_SOC_SERIES_SAME51 soc_samd5x.c)

soc/arm/atmel_sam0/common/Kconfig.saml2x

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (c) 2021 Argentum Systems Ltd.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
if SOC_SERIES_SAML21
4+
if SOC_SERIES_SAML21 || SOC_SERIES_SAMR34 || SOC_SERIES_SAMR35
55

66
config SOC_ATMEL_SAML_DEBUG_PAUSE
77
bool "Insert a pause at boot, to allow a debugger to attach"
@@ -71,4 +71,4 @@ config SOC_ATMEL_SAML_OSC16M_AS_MAIN
7171

7272
endchoice
7373

74-
endif # SOC_SERIES_SAML21
74+
endif # SOC_SERIES_SAML21 || SOC_SERIES_SAMR34 || SOC_SERIES_SAMR35
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2021 Argentum Systems Ltd.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/init.h>
8+
#include <zephyr/drivers/gpio.h>
9+
#include <soc.h>
10+
11+
#if !(ATMEL_SAM0_DT_SERCOM_CHECK(4, atmel_sam0_spi) && CONFIG_SPI_SAM0)
12+
/* When the radio is not in use, it's important that #CS is set high, to avoid
13+
* unexpected behavior and increased current consumption... see Chapter 10 of
14+
* DS70005356C. We also hold the radio in reset.
15+
*/
16+
static int soc_pinconf_init(const struct device *dev)
17+
{
18+
const struct device *portb = DEVICE_DT_GET(DT_NODELABEL(portb));
19+
20+
ARG_UNUSED(dev);
21+
22+
if (!device_is_ready(portb)) {
23+
return -ENODEV;
24+
}
25+
26+
gpio_pin_configure(portb, 31, GPIO_OUTPUT_HIGH);
27+
gpio_pin_configure(portb, 15, GPIO_OUTPUT_LOW);
28+
29+
return 0;
30+
}
31+
32+
SYS_INIT(soc_pinconf_init, PRE_KERNEL_2, 0);
33+
#endif
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Atmel SAML MCU series configuration options
2+
3+
# Copyright (c) 2021 Argentum Systems Ltd.
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
if SOC_SERIES_SAMR34
7+
8+
config SOC_SERIES
9+
default "samr34"
10+
11+
config SOC_PART_NUMBER
12+
default "samr34j16b" if SOC_PART_NUMBER_SAMR34J16B
13+
default "samr34j17b" if SOC_PART_NUMBER_SAMR34J17B
14+
default "samr34j18b" if SOC_PART_NUMBER_SAMR34J18B
15+
16+
config NUM_IRQS
17+
default 23
18+
19+
config SYS_CLOCK_HW_CYCLES_PER_SEC
20+
default $(dt_node_int_prop_int,/cpus/cpu@0,clock-frequency)
21+
22+
endif # SOC_SERIES_SAMR34
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Atmel SAMR34 MCU series
2+
3+
# Copyright (c) 2021 Argentum Systems Ltd.
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
config SOC_SERIES_SAMR34
7+
bool "Atmel SAMR34 MCU"
8+
select ARM
9+
select CPU_CORTEX_M0PLUS
10+
select SOC_FAMILY_SAM0
11+
select CPU_CORTEX_M_HAS_SYSTICK
12+
select CPU_CORTEX_M_HAS_VTOR
13+
select ASF
14+
help
15+
Enable support for Atmel SAMR34 Cortex-M0+ microcontrollers.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Atmel SAMR MCU series
2+
3+
# Copyright (c) 2021 Argentum Systems Ltd.
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
choice
7+
prompt "Atmel SAMR34 MCU Selection"
8+
depends on SOC_SERIES_SAMR34
9+
10+
config SOC_PART_NUMBER_SAMR34J16B
11+
bool "SAMR34J16B"
12+
13+
config SOC_PART_NUMBER_SAMR34J17B
14+
bool "SAMR34J17B"
15+
16+
config SOC_PART_NUMBER_SAMR34J18B
17+
bool "SAMR34J18B"
18+
19+
endchoice
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* linker.ld - Linker command/script file */
2+
3+
/*
4+
* Copyright (c) 2021 Argentum Systems Ltd.
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
#include <arch/arm/aarch32/cortex_m/scripts/linker.ld>

soc/arm/atmel_sam0/samr34/soc.h

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/* Copyright (c) 2021 Argentum Systems Ltd.
2+
*
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#ifndef _ATMEL_SAMR_SOC_H_
7+
#define _ATMEL_SAMR_SOC_H_
8+
9+
#ifndef _ASMLANGUAGE
10+
11+
#define DONT_USE_CMSIS_INIT
12+
13+
#include <zephyr/types.h>
14+
15+
#if defined(CONFIG_SOC_PART_NUMBER_SAMR34J16B)
16+
#include <samr34j16b.h>
17+
#elif defined(CONFIG_SOC_PART_NUMBER_SAMR34J17B)
18+
#include <samr34j17b.h>
19+
#elif defined(CONFIG_SOC_PART_NUMBER_SAMR34J18B)
20+
#include <samr34j18b.h>
21+
#else
22+
#error Library does not support the specified device.
23+
#endif
24+
25+
#endif /* _ASMLANGUAGE */
26+
27+
#include "adc_fixup_sam0.h"
28+
#include "../common/soc_port.h"
29+
#include "../common/atmel_sam0_dt.h"
30+
31+
/** Processor Clock (HCLK) Frequency */
32+
#define SOC_ATMEL_SAM0_HCLK_FREQ_HZ ATMEL_SAM0_DT_CPU_CLK_FREQ_HZ
33+
34+
/** Master Clock (MCK) Frequency */
35+
#define SOC_ATMEL_SAM0_MCK_FREQ_HZ SOC_ATMEL_SAM0_HCLK_FREQ_HZ
36+
#define SOC_ATMEL_SAM0_OSC32K_FREQ_HZ 32768
37+
#define SOC_ATMEL_SAM0_XOSC32K_FREQ_HZ 32768
38+
#define SOC_ATMEL_SAM0_OSC16M_FREQ_HZ 16000000
39+
#define SOC_ATMEL_SAM0_GCLK0_FREQ_HZ SOC_ATMEL_SAM0_MCK_FREQ_HZ
40+
#define SOC_ATMEL_SAM0_GCLK3_FREQ_HZ 24000000
41+
42+
#if defined(CONFIG_SOC_ATMEL_SAML_OPENLOOP_AS_MAIN)
43+
#define SOC_ATMEL_SAM0_GCLK1_FREQ_HZ 0
44+
#elif defined(CONFIG_SOC_ATMEL_SAML_OSC32K_AS_MAIN)
45+
#define SOC_ATMEL_SAM0_GCLK1_FREQ_HZ SOC_ATMEL_SAM0_OSC32K_FREQ_HZ
46+
#elif defined(CONFIG_SOC_ATMEL_SAML_XOSC32K_AS_MAIN)
47+
#define SOC_ATMEL_SAM0_GCLK1_FREQ_HZ SOC_ATMEL_SAM0_XOSC32K_FREQ_HZ
48+
#elif defined(CONFIG_SOC_ATMEL_SAML_OSC16M_AS_MAIN)
49+
#define SOC_ATMEL_SAM0_GCLK1_FREQ_HZ SOC_ATMEL_SAM0_OSC16M_FREQ_HZ
50+
#else
51+
#error Unsupported GCLK1 clock source.
52+
#endif
53+
54+
#define SOC_ATMEL_SAM0_APBA_FREQ_HZ SOC_ATMEL_SAM0_MCK_FREQ_HZ
55+
#define SOC_ATMEL_SAM0_APBB_FREQ_HZ SOC_ATMEL_SAM0_MCK_FREQ_HZ
56+
#define SOC_ATMEL_SAM0_APBC_FREQ_HZ SOC_ATMEL_SAM0_MCK_FREQ_HZ
57+
58+
#endif /* _ATMEL_SAMR_SOC_H_ */

0 commit comments

Comments
 (0)