Skip to content

Commit fed20f6

Browse files
committed
Fix for PWM on many pins, now works on: 5, 6, 9, 10, 11, 12, 13, 15 (A1), 16 (A2)
Merge remote-tracking branch 'upstream/master' Conflicts: cores/arduino/wiring_analog.c platform.txt
2 parents f6d0aaf + 66990f9 commit fed20f6

File tree

21 files changed

+268
-276
lines changed

21 files changed

+268
-276
lines changed

CHANGELOG

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
1-
SAMD CORE 1.6.6
1+
SAMD CORE
2+
3+
* Fixed Serial.flush() blocking before any writes. Thanks @hangmoh
4+
* Added snprintf_P to avr/pgmspace.h stub. Thanks @jantje
5+
* Another small fix to String iterators. Thanks @Ivan-Perez @Chris--A
6+
* Fixes SerialUSB.write(...) returning 0 instead of byte written
7+
* Added Uart::availableForWrite()
8+
* Added defines for RAMSTART, RAMSIZE, RAMEND
9+
* Fixed writing LOW to a digital input pin blocking subsequent digitalRead attempts
10+
* Fixed digitalWrite() unnecessarily activating the pull-up resistor
11+
* Wire: Slave writes now use TX buffer
12+
* Added getTimeout() method to Stream.
13+
* Fixed glitch in PWM generation that may happen when calling analogWrite()
14+
* PWM frequency is now 732.4Hz (before it was 187500.0Hz)
15+
16+
SAMD CORE 1.6.6 2016.05.19
217

318
* Fixed digitalPinToInterrupt() macro, now it works as documented.
419
* Added analogInputToDigitalPin macro
@@ -8,6 +23,7 @@ SAMD CORE 1.6.6
823
* Fixed Wire.write(0x00) "ambiguos method" error
924
* String class now supports iterators. Thanks @Chris--A
1025
* Remove enabling bootloader protection when burning bootloader. This enables WDT, so sketches do not work.
26+
* Added remote upload for Yun-Shield
1127

1228
SAMD CORE 1.6.5 2016.04.02
1329

cores/arduino/Arduino.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ typedef uint16_t word;
3535
//
3636
#include "avr/pgmspace.h"
3737
#include "avr/interrupt.h"
38+
#include "avr/io.h"
3839

3940
#include "binary.h"
4041
#include "itoa.h"

cores/arduino/Print.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ size_t Print::printFloat(double number, uint8_t digits)
245245
while (digits-- > 0)
246246
{
247247
remainder *= 10.0;
248-
int toPrint = int(remainder);
248+
unsigned int toPrint = (unsigned int)remainder;
249249
n += print(toPrint);
250250
remainder -= toPrint;
251251
}

cores/arduino/SERCOM.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ void SERCOM::enableUART()
104104

105105
void SERCOM::flushUART()
106106
{
107+
// Skip checking transmission completion if data register is empty
108+
if(isDataRegisterEmptyUART())
109+
return;
110+
107111
// Wait for transmission to complete
108112
while(!sercom->USART.INTFLAG.bit.TXC);
109113
}
@@ -553,11 +557,8 @@ bool SERCOM::sendDataSlaveWIRE(uint8_t data)
553557
//Send data
554558
sercom->I2CS.DATA.bit.DATA = data;
555559

556-
//Wait data transmission successful
557-
while(!sercom->I2CS.INTFLAG.bit.DRDY);
558-
559560
//Problems on line? nack received?
560-
if(sercom->I2CS.STATUS.bit.RXNACK)
561+
if(!sercom->I2CS.INTFLAG.bit.DRDY || sercom->I2CS.STATUS.bit.RXNACK)
561562
return false;
562563
else
563564
return true;

cores/arduino/Stream.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ class Stream : public Print
6666
// parsing methods
6767

6868
void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second
69-
69+
unsigned long getTimeout(void) { return _timeout; }
70+
7071
bool find(char *target); // reads data from the stream until the target string is found
7172
bool find(uint8_t *target) { return find ((char *)target); }
7273
// returns true if target string is found, false if timed out (see setTimeout)

cores/arduino/USB/CDC.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,13 @@ int Serial_::available(void)
202202
return (uint32_t)(CDC_SERIAL_BUFFER_SIZE + buffer->head - buffer->tail) % CDC_SERIAL_BUFFER_SIZE;
203203
}
204204

205+
int Serial_::availableForWrite(void)
206+
{
207+
// return the number of bytes left in the current bank,
208+
// always EP size - 1, because bank is flushed on every write
209+
return (EPX_SIZE - 1);
210+
}
211+
205212
int Serial_::peek(void)
206213
{
207214
ring_buffer *buffer = &cdc_rx_buffer;
@@ -236,8 +243,7 @@ int Serial_::read(void)
236243
unsigned char c = buffer->buffer[buffer->tail];
237244
buffer->tail = (uint32_t)(buffer->tail + 1) % CDC_SERIAL_BUFFER_SIZE;
238245
buffer->full = false;
239-
// if (usb.available(CDC_ENDPOINT_OUT))
240-
// accept();
246+
241247
return c;
242248
}
243249
}
@@ -262,7 +268,7 @@ size_t Serial_::write(const uint8_t *buffer, size_t size)
262268
{
263269
uint32_t r = usb.send(CDC_ENDPOINT_IN, buffer, size);
264270

265-
if (r == 0) {
271+
if (r > 0) {
266272
return r;
267273
} else {
268274
setWriteError();

cores/arduino/USB/USBAPI.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ class Serial_ : public Stream
118118
void end(void);
119119

120120
virtual int available(void);
121+
virtual int availableForWrite(void);
121122
virtual void accept(void);
122123
virtual int peek(void);
123124
virtual int read(void);

cores/arduino/USB/USBCore.cpp

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,6 @@ void USBDeviceClass::handleEndpoint(uint8_t ep)
262262
#if defined(CDC_ENABLED)
263263
if (ep == CDC_ENDPOINT_OUT)
264264
{
265-
// The RAM Buffer is empty: we can receive data
266-
//usbd.epBank0ResetReady(CDC_ENDPOINT_OUT);
267-
268265
// Handle received bytes
269266
if (available(CDC_ENDPOINT_OUT))
270267
Serial.accept();
@@ -463,10 +460,6 @@ void USBDeviceClass::initEP(uint32_t ep, uint32_t config)
463460
}
464461
else if (config == USB_ENDPOINT_TYPE_CONTROL)
465462
{
466-
// XXX: Needed?
467-
// usbd.epBank0DisableAutoZLP(ep);
468-
// usbd.epBank1DisableAutoZLP(ep);
469-
470463
// Setup Control OUT
471464
usbd.epBank0SetSize(ep, 64);
472465
usbd.epBank0SetAddress(ep, &udd_ep_out_cache_buffer[ep]);
@@ -614,46 +607,14 @@ uint8_t USBDeviceClass::armRecv(uint32_t ep)
614607
// Blocking Send of data to an endpoint
615608
uint32_t USBDeviceClass::send(uint32_t ep, const void *data, uint32_t len)
616609
{
610+
uint32_t written = 0;
617611
uint32_t length = 0;
618612

619613
if (!_usbConfiguration)
620614
return -1;
621615
if (len > 16384)
622616
return -1;
623617

624-
#if 0
625-
// This shortcut has some issues:
626-
// - sometimes it fails when sending an odd number of bytes (may be
627-
// due to memory alignment?)
628-
// - the data pointer should point to "stable" data (and this is not
629-
// guaranteed by caller, it may be some sort of temporary buffer)
630-
// - the SRAM is not guaranteed to start at 0x20000000
631-
632-
// All the above problems must be properly fixed before reenabling
633-
// this part
634-
635-
if ((unsigned int)data > 0x20000000)
636-
{
637-
// Buffer in RAM
638-
usbd.epBank1SetAddress(ep, (void *)data);
639-
usbd.epBank1SetMultiPacketSize(ep, 0);
640-
641-
usbd.epBank1SetByteCount(ep, len);
642-
643-
// Clear the transfer complete flag
644-
usbd.epBank1AckTransferComplete(ep);
645-
646-
// RAM buffer is full, we can send data (IN)
647-
usbd.epBank1SetReady(ep);
648-
649-
// Wait for transfer to complete
650-
while (!usbd.epBank1IsTransferComplete(ep)) {
651-
; // need fire exit.
652-
}
653-
return 0;
654-
}
655-
#endif
656-
657618
#ifdef PIN_LED_TXL
658619
digitalWrite(PIN_LED_TXL, LOW);
659620
txLEDPulse = TX_RX_LED_PULSE_MS;
@@ -684,10 +645,11 @@ uint32_t USBDeviceClass::send(uint32_t ep, const void *data, uint32_t len)
684645
while (!usbd.epBank1IsTransferComplete(ep)) {
685646
; // need fire exit.
686647
}
648+
written += length;
687649
len -= length;
688650
data = (char *)data + length;
689651
}
690-
return len;
652+
return written;
691653
}
692654

693655
uint32_t USBDeviceClass::armSend(uint32_t ep, const void* data, uint32_t len)

cores/arduino/Uart.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ int Uart::available()
7777
return rxBuffer.available();
7878
}
7979

80+
int Uart::availableForWrite()
81+
{
82+
return (sercom->isDataRegisterEmptyUART() ? 1 : 0);
83+
}
84+
8085
int Uart::peek()
8186
{
8287
return rxBuffer.peek();

cores/arduino/Uart.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Uart : public HardwareSerial
3232
void begin(unsigned long baudrate, uint16_t config);
3333
void end();
3434
int available();
35+
int availableForWrite();
3536
int peek();
3637
int read();
3738
void flush();

0 commit comments

Comments
 (0)