Skip to content

Commit e730a24

Browse files
author
ficeto
committed
Merge pull request #22 from Links2004/esp8266
pull SPI speed fix and uart overflow
2 parents fe5c667 + a372da1 commit e730a24

File tree

3 files changed

+25
-19
lines changed

3 files changed

+25
-19
lines changed

Diff for: hardware/esp8266com/esp8266/cores/esp8266/HardwareSerial.cpp

+20-16
Original file line numberDiff line numberDiff line change
@@ -392,30 +392,34 @@ void uart_ignore_char(char c) {
392392

393393
void uart0_write_char(char c) {
394394
if(&Serial != NULL && Serial.isTxEnabled()) {
395-
if(c == '\n') {
396-
Serial.write('\r');
397-
}
398-
Serial.write(c);
399-
} else {
400-
if(c == '\n') {
401-
USF(0) = '\r';
395+
if(Serial.availableForWrite() > 0) {
396+
if(c == '\n') {
397+
Serial.write('\r');
398+
}
399+
Serial.write(c);
400+
return;
402401
}
403-
USF(0) = c;
404402
}
403+
if(c == '\n') {
404+
USF(0) = '\r';
405+
}
406+
USF(0) = c;
405407
}
406408

407409
void uart1_write_char(char c) {
408410
if(&Serial1 != NULL && Serial1.isTxEnabled()) {
409-
if(c == '\n') {
410-
Serial1.write('\r');
411-
}
412-
Serial1.write(c);
413-
} else {
414-
if(c == '\n') {
415-
USF(1) = '\r';
411+
if(Serial1.availableForWrite() > 0) {
412+
if(c == '\n') {
413+
Serial1.write('\r');
414+
}
415+
Serial1.write(c);
416+
return;
416417
}
417-
USF(1) = c;
418418
}
419+
if(c == '\n') {
420+
USF(1) = '\r';
421+
}
422+
USF(1) = c;
419423
}
420424

421425
static int s_uart_debug_nr = UART0;

Diff for: hardware/esp8266com/esp8266/libraries/SPI/SPI.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,14 @@ void SPIClass::setBitOrder(uint8_t bitOrder) {
121121
* @return
122122
*/
123123
static uint32_t ClkRegToFreq(spiClk_t * reg) {
124-
return (F_CPU / ((reg->regPre + 1) * (reg->regN + 1)));
124+
return (SPI_MAX_SPEED / ((reg->regPre + 1) * (reg->regN + 1)));
125125
}
126126

127127
void SPIClass::setFrequency(uint32_t freq) {
128128
static uint32_t lastSetFrequency = 0;
129129
static uint32_t lastSetRegister = 0;
130130

131-
if(freq >= F_CPU) {
131+
if(freq >= SPI_MAX_SPEED) {
132132
setClockDivider(0x80000000);
133133
return;
134134
}
@@ -164,7 +164,7 @@ void SPIClass::setFrequency(uint32_t freq) {
164164
reg.regN = calN;
165165

166166
while(calPreVari++ <= 1) { // test different variants for Pre (we calculate in int so we miss the decimals, testing is the easyest and fastest way)
167-
calPre = (((F_CPU / (reg.regN + 1)) / freq) - 1) + calPreVari;
167+
calPre = (((SPI_MAX_SPEED / (reg.regN + 1)) / freq) - 1) + calPreVari;
168168
if(calPre > 0x1FFF) {
169169
reg.regPre = 0x1FFF; // 8191
170170
} else if(calPre <= 0) {

Diff for: hardware/esp8266com/esp8266/libraries/SPI/SPI.h

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
#define SPI_CLOCK_DIV64 0x04fc1001 //250 KHz
4646
#endif
4747

48+
#define SPI_MAX_SPEED (80000000L)
49+
4850
const uint8_t SPI_MODE0 = 0x00; ///< CPOL: 0 CPHA: 0
4951
const uint8_t SPI_MODE1 = 0x01; ///< CPOL: 0 CPHA: 1
5052
const uint8_t SPI_MODE2 = 0x10; ///< CPOL: 1 CPHA: 0

0 commit comments

Comments
 (0)