Skip to content

Commit b7e8602

Browse files
Merged latest Arduino SAMB UART and CDC code
1 parent 820b541 commit b7e8602

File tree

7 files changed

+149
-36
lines changed

7 files changed

+149
-36
lines changed

CHANGELOG

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
1-
PwFusion SAMD CORE 0.2.2 2022.05.25
1+
#PwFusion SAMD CORE 0.2.9 2022.10.09
2+
* Merged Latest USB and CDC librarys from arduino SAMD library
23

4+
5+
#PwFusion SAMD CORE 0.2.2 2022.05.25
36
* Added transmission complete interrupt to SERCOM.cpp
47
* Added writeBytesPending() function to Uart.cpp
58

6-
PwFusion SAMD CORE 0.2.1 2022.06.24
79

10+
#PwFusion SAMD CORE 0.2.1 2022.06.24
811
* Changed Wire SERCOM interrupts to weak linking to allow the user to override the callbacks
912

10-
PwFusion SAMD CORE 0.2.0 2022.05.25
1113

14+
#PwFusion SAMD CORE 0.2.0 2022.05.25
1215
* Added support for additional analog inputs and external interrupts to R3actor
1316
* Fixed defect in analogRead() to allow reading A11 input
1417

15-
PwFusion SAMD CORE 0.1.0 2022.03.07
1618

19+
#PwFusion SAMD CORE 0.1.0 2022.03.07
1720
* PwFusion R3actor production board support
1821
* Swapped Pin 1 and 0 (UART Rx and Tx) to match Feather pin assignment
1922

20-
PwFusion SAMD CORE 0.0.8 2022.02.21
2123

24+
#PwFusion SAMD CORE 0.0.8 2022.02.21
2225
* PwFusion R3actor board support
2326
* Tested bootloader and IO
2427

2528

26-
PwFusion SAMD CORE 0.0.1 2021.03.19
27-
29+
#PwFusion SAMD CORE 0.0.1 2021.03.19
2830
* First public release.
2931

1.57 MB
Binary file not shown.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
Copyright (c) 2020 Arduino. All right reserved.
3+
4+
This library is free software; you can redistribute it and/or
5+
modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either
7+
version 2.1 of the License, or (at your option) any later version.
8+
9+
This library is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
See the GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with this library; if not, write to the Free Software
16+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
#ifdef __cplusplus
20+
21+
#ifndef _SAFE_RING_BUFFER_
22+
#define _SAFE_RING_BUFFER_
23+
24+
#include <RingBuffer.h>
25+
#include "sync.h"
26+
27+
namespace arduino {
28+
29+
template <int N>
30+
class SafeRingBufferN : public RingBufferN<N>
31+
{
32+
public:
33+
int read_char();
34+
void store_char( uint8_t c ) ;
35+
};
36+
37+
typedef SafeRingBufferN<SERIAL_BUFFER_SIZE> SafeRingBuffer;
38+
39+
template <int N>
40+
int SafeRingBufferN<N>::read_char() {
41+
synchronized {
42+
return RingBufferN<N>::read_char();
43+
}
44+
45+
// We should never reached this line because the synchronized {} block gets
46+
// executed at least once. However the compiler gets confused and prints a
47+
// warning about control reaching the end of a non-void function. This
48+
// silences that warning.
49+
return -1;
50+
}
51+
52+
template <int N>
53+
void SafeRingBufferN<N>::store_char(uint8_t c) {
54+
synchronized {
55+
RingBufferN<N>::store_char(c);
56+
}
57+
}
58+
59+
}
60+
61+
#endif /* _SAFE_RING_BUFFER_ */
62+
#endif /* __cplusplus */

Source/cores/arduino/USB/SAMD21_USBDevice.h

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include <stdio.h>
2525
#include <stdint.h>
2626

27+
#include "sync.h"
28+
2729
typedef uint8_t ep_t;
2830

2931
class USBDevice_SAMD21G18x {
@@ -219,32 +221,6 @@ void USBDevice_SAMD21G18x::calibrate() {
219221
usb.PADCAL.bit.TRIM = pad_trim;
220222
}
221223

222-
/*
223-
* Synchronization primitives.
224-
* TODO: Move into a separate header file and make an API out of it
225-
*/
226-
227-
class __Guard {
228-
public:
229-
__Guard() : primask(__get_PRIMASK()), loops(1) {
230-
__disable_irq();
231-
}
232-
~__Guard() {
233-
if (primask == 0) {
234-
__enable_irq();
235-
// http://infocenter.arm.com/help/topic/com.arm.doc.dai0321a/BIHBFEIB.html
236-
__ISB();
237-
}
238-
}
239-
uint32_t enter() { return loops--; }
240-
private:
241-
uint32_t primask;
242-
uint32_t loops;
243-
};
244-
245-
#define synchronized for (__Guard __guard; __guard.enter(); )
246-
247-
248224
/*
249225
* USB EP generic handlers.
250226
*/

Source/cores/arduino/Uart.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#include "HardwareSerial.h"
2222
#include "SERCOM.h"
23-
#include "RingBuffer.h"
23+
#include "SafeRingBuffer.h"
2424

2525
#include <cstddef>
2626

@@ -47,8 +47,9 @@ class Uart : public HardwareSerial
4747

4848
private:
4949
SERCOM *sercom;
50-
RingBuffer rxBuffer;
51-
RingBuffer txBuffer;
50+
51+
arduino::SafeRingBufferN<SERIAL_BUFFER_SIZE> rxBuffer;
52+
arduino::SafeRingBufferN<SERIAL_BUFFER_SIZE> txBuffer;
5253

5354
uint8_t uc_pinRX;
5455
uint8_t uc_pinTX;

Source/cores/arduino/sync.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <stdint.h>
2+
3+
#ifndef _SYNC_H_
4+
#define _SYNC_H_
5+
/*
6+
* Synchronization primitives.
7+
* TODO: Move into a separate header file and make an API out of it
8+
*/
9+
10+
class __Guard {
11+
public:
12+
__Guard() : primask(__get_PRIMASK()), loops(1) {
13+
__disable_irq();
14+
}
15+
~__Guard() {
16+
if (primask == 0) {
17+
__enable_irq();
18+
// http://infocenter.arm.com/help/topic/com.arm.doc.dai0321a/BIHBFEIB.html
19+
__ISB();
20+
}
21+
}
22+
uint32_t enter() { return loops--; }
23+
private:
24+
uint32_t primask;
25+
uint32_t loops;
26+
};
27+
28+
#define synchronized for (__Guard __guard; __guard.enter(); )
29+
30+
#endif

package_pwfusion_samd_index.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,48 @@
257257
"version": "1.2.0"
258258
}
259259
]
260+
},
261+
{
262+
"name": "Playing With Fusion SAMD Boards",
263+
"architecture": "samd",
264+
"version": "0.2.3",
265+
"category": "Contributed",
266+
"url": "https://github.com/PlayingWithFusion/Arduino_SAMD/raw/main/Releases/PwFusion_SAMD_00.02.03.zip",
267+
"archiveFileName": "PwFusion_SAMD_00.02.03.zip",
268+
"checksum": "SHA-256:4FF21C8D6A39B7FF6D3FA712CBF689A97EE16508B9BCA81945B337600CE02F82",
269+
"size": "1647728",
270+
"boards": [
271+
{
272+
"name": "R3aktor M0 Logger"
273+
}
274+
],
275+
"toolsDependencies": [
276+
{
277+
"packager": "arduino",
278+
"name": "arm-none-eabi-gcc",
279+
"version": "7-2017q4"
280+
},
281+
{
282+
"packager": "arduino",
283+
"name": "bossac",
284+
"version": "1.7.0-arduino3"
285+
},
286+
{
287+
"packager": "arduino",
288+
"name": "openocd",
289+
"version": "0.10.0-arduino9"
290+
},
291+
{
292+
"packager": "arduino",
293+
"name": "CMSIS",
294+
"version": "4.5.0"
295+
},
296+
{
297+
"packager": "arduino",
298+
"name": "CMSIS-Atmel",
299+
"version": "1.2.0"
300+
}
301+
]
260302
}
261303
],
262304
"tools": []

0 commit comments

Comments
 (0)