Skip to content

Commit b9aa95d

Browse files
committed
Merged in changes from upstream SAMD CORE 1.6.16 2017.08.23
2 parents 7c28b40 + f2ac24f commit b9aa95d

22 files changed

+135
-71
lines changed

CHANGELOG

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
1.6.16: (identical to beta version 1.6.8-beta-b3)
2-
1.6.8-beta-b3:
3-
* Changed version numbering to match Arduino SAMD core to indicate which upstream changes have been merged in.
4-
Release version 1.6.7 then skips to 1.6.16. Beta version 1.6.8-beta-b3 became release version 1.6.16.
1+
1.6.16 (release version, same as 1.6.16-beta-b0):
2+
1.6.16-beta-b0:
53
* Added MattairTech Xeno support (64-pin D21, L21, and C21)
6-
* Merged in changes from upstream SAMD CORE 1.6.17 (not released yet):
7-
* Fix changing trigger mode (RISING/FALLING/...) in attachInterrupt(..) during runtime. Thanks @joverbee
8-
* Improved ISR response time. Thanks @joverbee
4+
* Changed version numbering to match Arduino SAMD core to indicate which upstream changes have been merged in.
5+
* Release version 1.6.7 then skips to 1.6.16. Beta version 1.6.8-beta-b2 skips to 1.6.16-beta-b0.
96
* Merged in changes from upstream SAMD CORE 1.6.16 2017.08.23:
107
* PWMs now can perform real 16-bit resolution if analogWriteResolution(16) is set. Thanks @Adminius
118
* USB CDC: fixed issue of available() getting stuck when receiving ZLP's
@@ -15,6 +12,8 @@
1512
* Fixed pgm_read_ptr compatibility macro. Thanks @nkrkv
1613
* Documentation updates
1714

15+
**Version numbering change**
16+
1817
1.6.8-beta-b2:
1918
* Added SD Card firmware loading support to the bootloader (4KB and 8KB)
2019
* Removed SDU library, as the bootloader now supports SD cards directly

README.md

+7-8
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,9 @@ CHANGELOG for details on upstream commits and MattairTech additions that have be
1818

1919
## What's New - Release Version (1.6.16)
2020

21-
* Changed version numbering to match Arduino SAMD core to indicate which upstream changes have been merged in.
22-
Release version 1.6.7 then skips to 1.6.16. Beta version 1.6.8-beta-b3 became 1.6.16.
2321
* Added MattairTech Xeno support (64-pin D21, L21, and C21)
24-
* Merged in changes from upstream SAMD CORE 1.6.17 (not released yet):
25-
* Fix changing trigger mode (RISING/FALLING/...) in attachInterrupt(..) during runtime. Thanks @joverbee
26-
* Improved ISR response time. Thanks @joverbee
22+
* Changed version numbering to match Arduino SAMD core to indicate which upstream changes have been merged in.
23+
* Release version 1.6.7 then skips to 1.6.16. Beta version 1.6.8-beta-b2 skips to 1.6.16-beta-b0.
2724
* Merged in changes from upstream SAMD CORE 1.6.16 2017.08.23:
2825
* PWMs now can perform real 16-bit resolution if analogWriteResolution(16) is set. Thanks @Adminius
2926
* USB CDC: fixed issue of available() getting stuck when receiving ZLP's
@@ -34,11 +31,13 @@ CHANGELOG for details on upstream commits and MattairTech additions that have be
3431
* Documentation updates
3532

3633

37-
## What's New - Beta Version (1.6.8-beta)
34+
## What's New - Beta Version (1.6.16-beta)
3835
**See Beta Builds section for installation instructions.**
3936

40-
**1.6.8-beta-b3:**
41-
*Beta version 1.6.8-beta-b3 became release version 1.6.16. See above*
37+
**1.6.16-beta-b0:**
38+
*Beta version 1.6.16-beta-b0 became release version 1.6.16. See above*
39+
40+
**Version numbering change**
4241

4342
**1.6.8-beta-b2:**
4443
* Added SD Card firmware loading support to the bootloader (4KB and 8KB)

bootloaders/zero/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ allow the build_all_bootloaders.sh script to select SD Card support.
355355

356356
#### Boards definitions:
357357

358-
* MT_D21E_rev_A, MT_D21E_rev_B, MT_D11, MT_D21J
358+
* Xeno, MT_D21E_rev_A, MT_D21E_rev_B, MT_D11, MT_D21J
359359
* arduino_zero, arduino_mkrzero, arduino_mkr1000, genuino_mkr1000, genuino_zero
360360
* Generic_x21E, Generic_x21G, Generic_x21J, Generic_D11D14AM, Generic_D11D14AS, Generic_D11C14A
361361

cores/arduino/Print.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,14 @@ size_t Print::printFloat(double number, uint8_t digits)
238238

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

244244
// Extract digits from the remainder one at a time
245245
while (digits-- > 0)
246246
{
247247
remainder *= 10.0;
248-
unsigned int toPrint = (unsigned int)remainder;
248+
unsigned int toPrint = (unsigned int)(remainder);
249249
n += print(toPrint);
250250
remainder -= toPrint;
251251
}

cores/arduino/Print.h

+9
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
#define DEC 10
2929
#define HEX 16
3030
#define OCT 8
31+
#ifdef BIN // Prevent warnings if BIN is previously defined in "iotnx4.h" or similar
32+
#undef BIN
33+
#endif
3134
#define BIN 2
3235

3336
class Print
@@ -54,6 +57,10 @@ class Print
5457
return write((const uint8_t *)buffer, size);
5558
}
5659

60+
// default to zero, meaning "a single write may block"
61+
// should be overriden by subclasses with buffering
62+
virtual int availableForWrite() { return 0; }
63+
5764
size_t print(const __FlashStringHelper *);
5865
size_t print(const String &);
5966
size_t print(const char[]);
@@ -78,6 +85,8 @@ class Print
7885
size_t println(double, int = 2);
7986
size_t println(const Printable&);
8087
size_t println(void);
88+
89+
virtual void flush() { /* Empty implementation for backward compatibility */ }
8190
};
8291

8392
#endif

cores/arduino/RingBuffer.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ int RingBuffer::available()
6767
return delta;
6868
}
6969

70+
int RingBuffer::availableForStore()
71+
{
72+
if (_iHead >= _iTail)
73+
return SERIAL_BUFFER_SIZE - 1 - _iHead + _iTail;
74+
else
75+
return _iTail - _iHead - 1;
76+
}
77+
7078
int RingBuffer::peek()
7179
{
7280
if(_iTail == _iHead)

cores/arduino/RingBuffer.h

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class RingBuffer
4040
void clear();
4141
int read_char();
4242
int available();
43+
int availableForStore();
4344
int peek();
4445
bool isFull();
4546

cores/arduino/SERCOM.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,16 @@ int SERCOM::writeDataUART(uint8_t data)
218218
return 1;
219219
}
220220

221+
void SERCOM::enableDataRegisterEmptyInterruptUART()
222+
{
223+
sercom->USART.INTENSET.reg |= SERCOM_USART_INTENSET_DRE;
224+
}
225+
226+
void SERCOM::disableDataRegisterEmptyInterruptUART()
227+
{
228+
sercom->USART.INTENCLR.reg = SERCOM_USART_INTENCLR_DRE;
229+
}
230+
221231
/* =========================
222232
* ===== Sercom SPI
223233
* =========================

cores/arduino/SERCOM.h

+2
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ class SERCOM
168168
int writeDataUART(uint8_t data) ;
169169
bool isUARTError() ;
170170
void acknowledgeUARTError() ;
171+
void enableDataRegisterEmptyInterruptUART();
172+
void disableDataRegisterEmptyInterruptUART();
171173

172174
/* ========== SPI ========== */
173175
void initSPI(SercomSpiTXPad mosi, SercomRXPad miso, SercomSpiCharSize charSize, SercomDataOrder dataOrder) ;

cores/arduino/Stream.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
#define PARSE_TIMEOUT 1000 // default number of milli-seconds to wait
2929

30-
// private method to read stream with timeout
30+
// protected method to read stream with timeout
3131
int Stream::timedRead()
3232
{
3333
int c;
@@ -39,7 +39,7 @@ int Stream::timedRead()
3939
return -1; // -1 indicates timeout
4040
}
4141

42-
// private method to peek stream with timeout
42+
// protected method to peek stream with timeout
4343
int Stream::timedPeek()
4444
{
4545
int c;

cores/arduino/Stream.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,14 @@ class Stream : public Print
5151
protected:
5252
unsigned long _timeout; // number of milliseconds to wait for the next char before aborting timed read
5353
unsigned long _startMillis; // used for timeout measurement
54-
int timedRead(); // private method to read stream with timeout
55-
int timedPeek(); // private method to peek stream with timeout
54+
int timedRead(); // read stream with timeout
55+
int timedPeek(); // peek stream with timeout
5656
int peekNextDigit(LookaheadMode lookahead, bool detectDecimal); // returns the next numeric digit in the stream or -1 if timeout
5757

5858
public:
5959
virtual int available() = 0;
6060
virtual int read() = 0;
6161
virtual int peek() = 0;
62-
virtual void flush() = 0;
6362

6463
Stream() {_timeout=1000;}
6564

cores/arduino/USB/USBCore.cpp

+21-1
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,15 @@ uint32_t USBDeviceClass::sendConfiguration(uint32_t maxlen)
184184
return true;
185185
}
186186

187+
static void utox8(uint32_t val, char* s) {
188+
for (int i = 0; i < 8; i++) {
189+
int d = val & 0XF;
190+
val = (val >> 4);
191+
192+
s[7 - i] = d > 9 ? 'A' + d - 10 : '0' + d;
193+
}
194+
}
195+
187196
bool USBDeviceClass::sendDescriptor(USBSetup &setup)
188197
{
189198
uint8_t t = setup.wValueH;
@@ -231,8 +240,19 @@ bool USBDeviceClass::sendDescriptor(USBSetup &setup)
231240
}
232241
else if (setup.wValueL == ISERIAL) {
233242
#ifdef PLUGGABLE_USB_ENABLED
243+
// from section 9.3.3 of the datasheet
244+
#define SERIAL_NUMBER_WORD_0 *(volatile uint32_t*)(0x0080A00C)
245+
#define SERIAL_NUMBER_WORD_1 *(volatile uint32_t*)(0x0080A040)
246+
#define SERIAL_NUMBER_WORD_2 *(volatile uint32_t*)(0x0080A044)
247+
#define SERIAL_NUMBER_WORD_3 *(volatile uint32_t*)(0x0080A048)
248+
234249
char name[ISERIAL_MAX_LEN];
235-
PluggableUSB().getShortName(name);
250+
utox8(SERIAL_NUMBER_WORD_0, &name[0]);
251+
utox8(SERIAL_NUMBER_WORD_1, &name[8]);
252+
utox8(SERIAL_NUMBER_WORD_2, &name[16]);
253+
utox8(SERIAL_NUMBER_WORD_3, &name[24]);
254+
255+
PluggableUSB().getShortName(&name[32]);
236256
return sendStringDescriptor((uint8_t*)name, setup.wLength);
237257
#endif
238258
}

cores/arduino/USB/USBDesc.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#define CDC_TX CDC_ENDPOINT_IN
4545
#endif
4646

47-
#define ISERIAL_MAX_LEN 33
47+
#define ISERIAL_MAX_LEN 65
4848

4949
// Defined string description
5050
#define IMANUFACTURER 1

cores/arduino/Uart.cpp

+24-2
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,13 @@ void Uart::end()
5050
{
5151
sercom->resetUART();
5252
rxBuffer.clear();
53+
txBuffer.clear();
5354
}
5455

5556
void Uart::flush()
5657
{
58+
while(txBuffer.available()); // wait until TX buffer is empty
59+
5760
sercom->flushUART();
5861
}
5962

@@ -63,6 +66,16 @@ void Uart::IrqHandler()
6366
rxBuffer.store_char(sercom->readDataUART());
6467
}
6568

69+
if (sercom->isDataRegisterEmptyUART()) {
70+
if (txBuffer.available()) {
71+
uint8_t data = txBuffer.read_char();
72+
73+
sercom->writeDataUART(data);
74+
} else {
75+
sercom->disableDataRegisterEmptyInterruptUART();
76+
}
77+
}
78+
6679
if (sercom->isUARTError()) {
6780
sercom->acknowledgeUARTError();
6881
// TODO: if (sercom->isBufferOverflowErrorUART()) ....
@@ -79,7 +92,7 @@ int Uart::available()
7992

8093
int Uart::availableForWrite()
8194
{
82-
return (sercom->isDataRegisterEmptyUART() ? 1 : 0);
95+
return txBuffer.availableForStore();
8396
}
8497

8598
int Uart::peek()
@@ -94,7 +107,16 @@ int Uart::read()
94107

95108
size_t Uart::write(const uint8_t data)
96109
{
97-
sercom->writeDataUART(data);
110+
if (sercom->isDataRegisterEmptyUART() && txBuffer.available() == 0) {
111+
sercom->writeDataUART(data);
112+
} else {
113+
while(txBuffer.isFull()); // spin lock until a spot opens up in the buffer
114+
115+
txBuffer.store_char(data);
116+
117+
sercom->enableDataRegisterEmptyInterruptUART();
118+
}
119+
98120
return 1;
99121
}
100122

cores/arduino/Uart.h

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class Uart : public HardwareSerial
4646
private:
4747
SERCOM *sercom;
4848
RingBuffer rxBuffer;
49+
RingBuffer txBuffer;
4950

5051
uint8_t uc_pinRX;
5152
uint8_t uc_pinTX;

cores/arduino/avr/pgmspace.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ typedef const void* uint_farptr_t;
103103
#define pgm_read_word(addr) (*(const unsigned short *)(addr))
104104
#define pgm_read_dword(addr) (*(const unsigned long *)(addr))
105105
#define pgm_read_float(addr) (*(const float *)(addr))
106-
#define pgm_read_ptr(addr) (*(const void *)(addr))
106+
#define pgm_read_ptr(addr) (*(const void **)(addr))
107107

108108
#define pgm_read_byte_near(addr) pgm_read_byte(addr)
109109
#define pgm_read_word_near(addr) pgm_read_word(addr)

cores/arduino/delay.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ extern "C" {
2626
/** Tick Counter united by ms */
2727
static volatile uint32_t _ulTickCount=0 ;
2828

29-
uint32_t millis( void )
29+
unsigned long millis( void )
3030
{
3131
// todo: ensure no interrupts
3232
return _ulTickCount ;
@@ -36,7 +36,7 @@ uint32_t millis( void )
3636
// Theory: repeatedly take readings of SysTick counter, millis counter and SysTick interrupt pending flag.
3737
// When it appears that millis counter and pending is stable and SysTick hasn't rolled over, use these
3838
// values to calculate micros. If there is a pending SysTick, add one to the millis counter in the calculation.
39-
uint32_t micros( void )
39+
unsigned long micros( void )
4040
{
4141
uint32_t ticks, ticks2;
4242
uint32_t pend, pend2;
@@ -61,7 +61,7 @@ uint32_t micros( void )
6161
// a runtime multiplication and shift, saving a few cycles
6262
}
6363

64-
void delay( uint32_t ms )
64+
void delay( unsigned long ms )
6565
{
6666
if ( ms == 0 )
6767
{

cores/arduino/delay.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extern "C" {
3333
*
3434
* \return Number of milliseconds since the program started (uint32_t)
3535
*/
36-
extern uint32_t millis( void ) ;
36+
extern unsigned long millis( void ) ;
3737

3838
/**
3939
* \brief Returns the number of microseconds since the Arduino board began running the current program.
@@ -45,23 +45,23 @@ extern uint32_t millis( void ) ;
4545
*
4646
* \note There are 1,000 microseconds in a millisecond and 1,000,000 microseconds in a second.
4747
*/
48-
extern uint32_t micros( void ) ;
48+
extern unsigned long micros( void ) ;
4949

5050
/**
5151
* \brief Pauses the program for the amount of time (in miliseconds) specified as parameter.
5252
* (There are 1000 milliseconds in a second.)
5353
*
5454
* \param dwMs the number of milliseconds to pause (uint32_t)
5555
*/
56-
extern void delay( uint32_t dwMs ) ;
56+
extern void delay( unsigned long dwMs ) ;
5757

5858
/**
5959
* \brief Pauses the program for the amount of time (in microseconds) specified as parameter.
6060
*
6161
* \param dwUs the number of microseconds to pause (uint32_t)
6262
*/
63-
static __inline__ void delayMicroseconds( uint32_t ) __attribute__((always_inline, unused)) ;
64-
static __inline__ void delayMicroseconds( uint32_t usec )
63+
static __inline__ void delayMicroseconds( unsigned int ) __attribute__((always_inline, unused)) ;
64+
static __inline__ void delayMicroseconds( unsigned int usec )
6565
{
6666
if ( usec == 0 )
6767
{

0 commit comments

Comments
 (0)