Skip to content

Draft: Add SAM4E 4S support #141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 59 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
42f32d9
use files from SAM4S Motionbow project
chepo92 Sep 10, 2023
c0342fd
add package.json for pio integration
chepo92 Sep 10, 2023
d460b6d
Merge branch 'master' into dev-SAM4SCore
chepo92 Sep 10, 2023
b24b145
save arduino output cmd
chepo92 Sep 10, 2023
b38a5bd
dump version to 0 so i can install/use different versions
chepo92 Sep 10, 2023
b1084a7
save more output for different boards and cores
chepo92 Sep 11, 2023
23a7cf9
add instruction
chepo92 Sep 11, 2023
703074b
fix based on issue
chepo92 Sep 11, 2023
e3aa69a
modified variant sam4
chepo92 Sep 15, 2023
b69d95c
linker
chepo92 Sep 15, 2023
25ecb20
added CMSIS SAM4e files from klipper
chepo92 Sep 15, 2023
a018b76
add board defs
chepo92 Sep 15, 2023
6e73b70
afec was including PDC offsets
chepo92 Sep 15, 2023
ef94e27
moved out sam4s files from 4e variant
chepo92 Sep 15, 2023
efe9ab2
rm motionbow dbg
chepo92 Sep 15, 2023
79beaa4
Revert "rm motionbow dbg"
chepo92 Sep 15, 2023
3325389
sam4e includes defs
chepo92 Sep 15, 2023
51f2455
afec as adc
chepo92 Sep 15, 2023
a97fa79
some mods as using AFE as ADC
chepo92 Sep 15, 2023
a9206bc
modify libsam for sam4e
chepo92 Sep 15, 2023
d8023f3
modify variant
chepo92 Sep 15, 2023
78694c5
update part of the core
chepo92 Sep 15, 2023
e796fb0
linker sam4e series
chepo92 Sep 25, 2023
e63a2ae
name
chepo92 Sep 26, 2023
0711df5
correct arch conditionals
chepo92 Sep 26, 2023
c686865
conditional for SAM 4S or 4E
chepo92 Sep 27, 2023
f0e476f
resolve UDP name conflic based on sam4s solution
chepo92 Sep 27, 2023
2daa25d
conditionals for SAM4S and 4e
chepo92 Sep 29, 2023
b0a9194
rename for ADC solution
chepo92 Sep 29, 2023
3cbcc36
add TC path
chepo92 Sep 29, 2023
c738c92
chip and pjony
chepo92 Sep 29, 2023
268776d
some comments
chepo92 Sep 29, 2023
8730727
change AFEC0 for ADC as a start
chepo92 Sep 29, 2023
654ef2e
add Register Peripheral DMA Controller (PDC) reg as in SAM4S
chepo92 Sep 29, 2023
3d07f8e
Adapt defs of sam4e to 4s
chepo92 Sep 30, 2023
05f2388
conditionals for SAM4 implementation
chepo92 Sep 30, 2023
caf2c28
removed ssc, sam4e doen't have
chepo92 Sep 30, 2023
ebcd49e
conditional include
chepo92 Sep 30, 2023
50977dd
disable USB PLLB usage, will resolve later
chepo92 Sep 30, 2023
fc9eb8e
copy startup SAM4S for SAM4E
chepo92 Sep 30, 2023
8ceb294
startup SAM4S
chepo92 Sep 30, 2023
d2f7ca3
SAM4E do not have PLLB
chepo92 Sep 30, 2023
178a06e
usa SAM4E from github as base, include parts of SAM4S
chepo92 Sep 30, 2023
7023753
rename to sartup sam4e
chepo92 Sep 30, 2023
9ecfb95
conditionals for SAM4E
chepo92 Sep 30, 2023
c476345
missing #define SAM3_SERIES
chepo92 Sep 30, 2023
257bc2e
conditional PIO interrupts for SAM4E
chepo92 Sep 30, 2023
aea9197
conditional PIO interrupts for SAM4E 2nd part
chepo92 Sep 30, 2023
12c3969
peripheral SAM4E PIOE
chepo92 Sep 30, 2023
ca10b04
make libsam output to sam4e8e variant folder
chepo92 Sep 30, 2023
5e56cc8
startup cortex handlers contitionals for sam4e
chepo92 Sep 30, 2023
42adece
add pins for testing
chepo92 Sep 30, 2023
b966546
make only sam4e
chepo92 Sep 30, 2023
0bec8d7
libsam 4e8e, compiles, but is it working?
chepo92 Sep 30, 2023
81c5ed8
libsam build
chepo92 Sep 30, 2023
e7a9060
change dummy for 0UL
chepo92 Sep 30, 2023
9653b49
startup update
chepo92 Sep 30, 2023
a9c1b3d
Example code for blinking LED
chepo92 Sep 30, 2023
8f59856
update readme
chepo92 Oct 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
137 changes: 137 additions & 0 deletions ArduinoIDEoutput.md

Large diffs are not rendered by default.

28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Arduino Core for SAM3X CPU
# Arduino Core for SAM3 and SAM4 CPU

This repository contains the source code and configuration files of the Arduino Core for Atmel's SAM3X processor (used on the [Arduino Due](https://www.arduino.cc/en/Main/ArduinoBoardDue) board).

Expand All @@ -9,6 +9,31 @@ Just open the "Boards Manager" and install the package called:

* **Arduino SAM Boards (32-bit ARM Cortex-M3)**

## Installation on VSCode

Use Platformio extension with atmelsam framework

```
[env:due]
platform = atmelsam
framework = arduino
board = due

```

Development SAM4E Version

```
[env:SAM4]
platform = atmelsam
framework = arduino
board = sam4e8e
platform_packages =
framework-arduino-sam@https://github.com/chepo92/ArduinoCore-sam.git#dev-SAM4E
toolchain-gccarmnoneeabi @ 1.40804.0

```

## Support

There is a dedicated section of the Arduino Forum for general discussion and project assistance:
Expand All @@ -27,3 +52,4 @@ Before posting a new issue, please check if the same problem has been already re

Contributions are always welcome.
The preferred way to receive code contribution is by submitting a Pull Request on github.

90 changes: 42 additions & 48 deletions boards.txt
Original file line number Diff line number Diff line change
@@ -1,49 +1,43 @@
motionbow.name=Motionbow
motionbow.vid.0=0x2341
motionbow.pid.0=0x003e
motionbow.upload.tool=bossac
motionbow.upload.protocol=sam-ba
motionbow.upload.maximum_size=262144
motionbow.upload.use_1200bps_touch=true
motionbow.upload.wait_for_upload_port=true
motionbow.upload.native_usb=true
motionbow.build.mcu=cortex-m4
motionbow.build.f_cpu=120000000ul
motionbow.build.usb_manufacturer="LaserX"
motionbow.build.usb_product="laserX bow"
motionbow.build.board=MOTIONBOW
motionbow.build.core=arduino
motionbow.build.extra_flags=-D__SAM4S4A__ -mthumb {build.usb_flags}
motionbow.build.ldscript=linker_scripts/gcc/flash.ld
motionbow.build.variant=motionbow
motionbow.build.variant_system_lib=libsam_sam4s4a_gcc_rel.a
motionbow.build.vid=0x2341
motionbow.build.pid=0x003e

arduino_due_x_dbg.name=Arduino Due (Programming Port)
arduino_due_x_dbg.vid.0=0x2341
arduino_due_x_dbg.pid.0=0x003d
arduino_due_x_dbg.vid.1=0x2A03
arduino_due_x_dbg.pid.1=0x003d
arduino_due_x_dbg.upload.tool=bossac
arduino_due_x_dbg.upload.protocol=sam-ba
arduino_due_x_dbg.upload.maximum_size=524288
arduino_due_x_dbg.upload.use_1200bps_touch=true
arduino_due_x_dbg.upload.wait_for_upload_port=false
arduino_due_x_dbg.upload.native_usb=false
arduino_due_x_dbg.build.mcu=cortex-m3
arduino_due_x_dbg.build.f_cpu=84000000L
arduino_due_x_dbg.build.usb_manufacturer="Arduino LLC"
arduino_due_x_dbg.build.usb_product="Arduino Due"
arduino_due_x_dbg.build.board=SAM_DUE
arduino_due_x_dbg.build.core=arduino
arduino_due_x_dbg.build.extra_flags=-D__SAM3X8E__ -mthumb {build.usb_flags}
arduino_due_x_dbg.build.ldscript=linker_scripts/gcc/flash.ld
arduino_due_x_dbg.build.variant=arduino_due_x
arduino_due_x_dbg.build.variant_system_lib=libsam_sam3x8e_gcc_rel.a
arduino_due_x_dbg.build.vid=0x2341
arduino_due_x_dbg.build.pid=0x003e

arduino_due_x.name=Arduino Due (Native USB Port)
arduino_due_x.vid.0=0x2341
arduino_due_x.pid.0=0x003e
arduino_due_x.vid.1=0x2A03
arduino_due_x.pid.1=0x003e
arduino_due_x.upload.tool=bossac
arduino_due_x.upload.protocol=sam-ba
arduino_due_x.upload.maximum_size=524288
arduino_due_x.upload.use_1200bps_touch=true
arduino_due_x.upload.wait_for_upload_port=true
arduino_due_x.upload.native_usb=true
arduino_due_x.build.mcu=cortex-m3
arduino_due_x.build.f_cpu=84000000L
arduino_due_x.build.usb_manufacturer="Arduino LLC"
arduino_due_x.build.usb_product="Arduino Due"
arduino_due_x.build.board=SAM_DUE
arduino_due_x.build.core=arduino
arduino_due_x.build.extra_flags=-D__SAM3X8E__ -mthumb {build.usb_flags}
arduino_due_x.build.ldscript=linker_scripts/gcc/flash.ld
arduino_due_x.build.variant=arduino_due_x
arduino_due_x.build.variant_system_lib=libsam_sam3x8e_gcc_rel.a
arduino_due_x.build.vid=0x2341
arduino_due_x.build.pid=0x003e

sam4e8e.name=SAM4E8E
sam4e8e.vid.0=0x2341
sam4e8e.pid.0=0x003e
sam4e8e.upload.tool=bossac
sam4e8e.upload.protocol=sam-ba
sam4e8e.upload.maximum_size=262144
sam4e8e.upload.use_1200bps_touch=true
sam4e8e.upload.wait_for_upload_port=true
sam4e8e.upload.native_usb=true
sam4e8e.build.mcu=cortex-m4
sam4e8e.build.f_cpu=120000000ul
sam4e8e.build.usb_manufacturer="LaserX"
sam4e8e.build.usb_product="laserX bow"
sam4e8e.build.board=SAM4E8E
sam4e8e.build.core=arduino
sam4e8e.build.extra_flags=-D__SAM4E8E__ -mthumb {build.usb_flags}
sam4e8e.build.ldscript=linker_scripts/gcc/flash.ld
sam4e8e.build.variant=sam4e8e
sam4e8e.build.variant_system_lib=libsam_sam4e8e_gcc_rel.a
sam4e8e.build.vid=0x2341
sam4e8e.build.pid=0x003e
11 changes: 11 additions & 0 deletions cores/arduino/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ void yield(void);
extern void setup( void ) ;
extern void loop( void ) ;












//#define NOT_A_PIN 0 // defined in pio.h/EPioType
#define NOT_A_PORT 0

Expand Down
9 changes: 6 additions & 3 deletions cores/arduino/HardwareSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@
class HardwareSerial : public Stream
{
public:
virtual void begin(unsigned long);
virtual void end();
virtual void begin(unsigned long) = 0; // unsigned long
virtual void end() = 0;

virtual int available(void) = 0;

virtual int peek(void) = 0;
virtual int read(void) = 0;
virtual int read(void) = 0;
virtual void flush(void) = 0;

virtual size_t write(uint8_t) = 0;
using Print::write; // pull in write(str) and write(buf, size) from Print
virtual operator bool() = 0;
Expand Down
2 changes: 2 additions & 0 deletions cores/arduino/IPAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ IPAddress::IPAddress(const uint8_t *address)

bool IPAddress::fromString(const char *address)
{
// TODO: add support for "a", "a.b", "a.b.c" formats

uint16_t acc = 0; // Accumulator
uint8_t dots = 0;

Expand Down
2 changes: 1 addition & 1 deletion cores/arduino/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ size_t Print::printFloat(double number, uint8_t digits)

// Print the decimal point, but only if there are digits beyond
if (digits > 0) {
n += print('.');
n += print(".");
}

// Extract digits from the remainder one at a time
Expand Down
33 changes: 31 additions & 2 deletions cores/arduino/Reset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,51 @@
extern "C" {
#endif

#ifdef SAM4_SERIES

#define EEFC_FCR_FCMD(value) ((EEFC_FCR_FCMD_Msk & ((value) << EEFC_FCR_FCMD_Pos)))
#define EEFC_FCR_FKEY(value) ((EEFC_FCR_FKEY_Msk & ((value) << EEFC_FCR_FKEY_Pos)))
#define RSTC_CR_KEY(value) ((RSTC_CR_KEY_Msk & ((value) << RSTC_CR_KEY_Pos)))

#endif


__attribute__ ((long_call, section (".ramfunc")))
void banzai() {
// Disable all interrupts
__disable_irq();

// Set bootflag to run SAM-BA bootloader at restart
const int EEFC_FCMD_CGPB = 0x0C;
const int EEFC_KEY = 0x5A;
const int EEFC_FCMD_CGPB = 0x0C; // Clear GPNVM bit
const int EEFC_KEY = 0x5A; // FKEY: Flash Writing Protection Key
#if SAM4S_SERIES

while ((EFC0->EEFC_FSR & EEFC_FSR_FRDY) == 0);
EFC0->EEFC_FCR =
EEFC_FCR_FCMD(EEFC_FCMD_CGPB) |
EEFC_FCR_FARG(1) |
EEFC_FCR_FKEY(EEFC_KEY);
while ((EFC0->EEFC_FSR & EEFC_FSR_FRDY) == 0);

#elif SAM4E_SERIES
#warning SAM4E_SERIES Enabled
while ((EFC->EEFC_FSR & EEFC_FSR_FRDY) == 0);
EFC->EEFC_FCR =
EEFC_FCR_FCMD(EEFC_FCMD_CGPB) |
EEFC_FCR_FARG(1) |
EEFC_FCR_FKEY(EEFC_KEY);
while ((EFC->EEFC_FSR & EEFC_FSR_FRDY) == 0);

#endif


// From here flash memory is no more available.

// Memory swap needs some time to stabilize
for (uint32_t i=0; i<1000000; i++)
// force compiler to not optimize this
__asm__ __volatile__("");

// BANZAIIIIIII!!!
const int RSTC_KEY = 0xA5;
RSTC->RSTC_CR =
Expand All @@ -54,6 +82,7 @@ static int ticks = -1;

void initiateReset(int _ticks) {
ticks = _ticks;
//banzai();
}

void cancelReset() {
Expand Down
2 changes: 1 addition & 1 deletion cores/arduino/RingBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <stdint.h>

// Define constants and variables for buffering incoming serial data. We're
// using a ring buffer, in which head is the index of the location
// using a ring buffer (I think), in which head is the index of the location
// to which to write the next incoming character and tail is the index of the
// location from which to read.
#define SERIAL_BUFFER_SIZE 128
Expand Down
5 changes: 3 additions & 2 deletions cores/arduino/Stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
#include "Stream.h"

#define PARSE_TIMEOUT 1000 // default number of milli-seconds to wait
#define NO_SKIP_CHAR 1 // a magic char not found in a valid ASCII numeric field

// protected method to read stream with timeout
// private method to read stream with timeout
int Stream::timedRead()
{
int c;
Expand All @@ -39,7 +40,7 @@ int Stream::timedRead()
return -1; // -1 indicates timeout
}

// protected method to peek stream with timeout
// private method to peek stream with timeout
int Stream::timedPeek()
{
int c;
Expand Down
4 changes: 2 additions & 2 deletions cores/arduino/Stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class Stream : public Print
protected:
unsigned long _timeout; // number of milliseconds to wait for the next char before aborting timed read
unsigned long _startMillis; // used for timeout measurement
int timedRead(); // read stream with timeout
int timedPeek(); // peek stream with timeout
int timedRead(); // private method to read stream with timeout
int timedPeek(); // private method to peek stream with timeout
int peekNextDigit(LookaheadMode lookahead, bool detectDecimal); // returns the next numeric digit in the stream or -1 if timeout

public:
Expand Down
Loading