Skip to content

Commit f1e2cba

Browse files
committed
Merge remote-tracking branch 'refs/remotes/rogerclarkmelbourne/master' into generic_f4
# Conflicts: # .gitignore
2 parents b7fb21a + 6fa060c commit f1e2cba

22 files changed

Lines changed: 998 additions & 215 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ other/maple-bootloader/*~
88
*.o
99
tools/src/stm32flash_serial/src/parsers/parsers.a
1010
*.bak
11+
*.1

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ This repo contains, the "Hardware" files to support STM32 based boards on Arduin
1313

1414
***PRIMARY SUPPORT FORUM: http://www.stm32duino.com/***
1515

16+
***We are also on Gitter https://gitter.im/stm32duino/Lobby/***
17+
1618
##Background & Support:
1719
* Based on https://github.com/bobc/maple-asp, which is in turn based on LibMaple by Leaflabs
1820
* **Please read the wiki (https://github.com/rogerclarkmelbourne/Arduino_STM32/wiki) for full details**

STM32F1/cores/maple/libmaple/dma_f1.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ void dma_set_per_addr(dma_dev *dev, dma_channel channel, __io void *addr) {
341341
* @see dma_attach_interrupt()
342342
* @see dma_enable()
343343
*/
344-
__deprecated
345344
void dma_setup_transfer(dma_dev *dev,
346345
dma_channel channel,
347346
__io void *peripheral_address,

STM32F1/cores/maple/libmaple/spi.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void spi_slave_enable(spi_dev *dev, spi_mode mode, uint32 flags) {
8484
}
8585

8686
/**
87-
* @brief Nonblocking SPI transmit.
87+
* @brief Blocking SPI transmit.
8888
* @param dev SPI port to use for transmission
8989
* @param buf Buffer to transmit. The sizeof buf's elements are
9090
* inferred from dev's data frame format (i.e., are
@@ -93,15 +93,21 @@ void spi_slave_enable(spi_dev *dev, spi_mode mode, uint32 flags) {
9393
* @return Number of elements transmitted.
9494
*/
9595
uint32 spi_tx(spi_dev *dev, const void *buf, uint32 len) {
96-
uint32 txed = 0;
97-
uint8 byte_frame = spi_dff(dev) == SPI_DFF_8_BIT;
98-
while (spi_is_tx_empty(dev) && (txed < len)) {
99-
if (byte_frame) {
100-
dev->regs->DR = ((const uint8*)buf)[txed++];
101-
} else {
102-
dev->regs->DR = ((const uint16*)buf)[txed++];
103-
}
104-
}
96+
uint32 txed = len;
97+
spi_reg_map *regs = dev->regs;
98+
if ( spi_dff(dev) == SPI_DFF_8_BIT ) {
99+
const uint8 * dp8 = (const uint8*)buf;
100+
while ( len-- ) {
101+
while ( (regs->SR & SPI_SR_TXE)==0 ) ; //while ( spi_is_tx_empty(dev)==0 ); // wait Tx to be empty
102+
regs->DR = *dp8++;
103+
}
104+
} else {
105+
const uint16 * dp16 = (const uint16*)buf;
106+
while ( len-- ) {
107+
while ( (regs->SR & SPI_SR_TXE)==0 ) ; //while ( spi_is_tx_empty(dev)==0 ); // wait Tx to be empty
108+
regs->DR = *dp16++;
109+
}
110+
}
105111
return txed;
106112
}
107113

STM32F1/cores/maple/usb_serial.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ static void ifaceSetupHook(unsigned, void*);
5454
*/
5555

5656
#define USB_TIMEOUT 50
57+
#if BOARD_HAVE_SERIALUSB
58+
bool USBSerial::_hasBegun = false;
59+
#endif
5760

5861
USBSerial::USBSerial(void) {
5962
#if !BOARD_HAVE_SERIALUSB
@@ -62,7 +65,12 @@ USBSerial::USBSerial(void) {
6265
}
6366

6467
void USBSerial::begin(void) {
68+
6569
#if BOARD_HAVE_SERIALUSB
70+
if (_hasBegun)
71+
return;
72+
_hasBegun = true;
73+
6674
usb_cdcacm_enable(BOARD_USB_DISC_DEV, BOARD_USB_DISC_BIT);
6775
usb_cdcacm_set_hooks(USB_CDCACM_HOOK_RX, rxHook);
6876
usb_cdcacm_set_hooks(USB_CDCACM_HOOK_IFACE_SETUP, ifaceSetupHook);
@@ -75,6 +83,7 @@ void USBSerial::begin(unsigned long ignoreBaud)
7583
volatile unsigned long removeCompilerWarningsIgnoreBaud=ignoreBaud;
7684

7785
ignoreBaud=removeCompilerWarningsIgnoreBaud;
86+
begin();
7887
}
7988
void USBSerial::begin(unsigned long ignoreBaud, uint8_t ignore)
8089
{
@@ -83,13 +92,16 @@ volatile uint8_t removeCompilerWarningsIgnore=ignore;
8392

8493
ignoreBaud=removeCompilerWarningsIgnoreBaud;
8594
ignore=removeCompilerWarningsIgnore;
95+
begin();
8696
}
8797

8898
void USBSerial::end(void) {
8999
#if BOARD_HAVE_SERIALUSB
90100
usb_cdcacm_disable(BOARD_USB_DISC_DEV, BOARD_USB_DISC_BIT);
91101
usb_cdcacm_remove_hooks(USB_CDCACM_HOOK_RX | USB_CDCACM_HOOK_IFACE_SETUP);
102+
_hasBegun = false;
92103
#endif
104+
93105
}
94106

95107
size_t USBSerial::write(uint8 ch) {

STM32F1/cores/maple/usb_serial.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ class USBSerial : public Stream {
7171
uint8 getDTR();
7272
uint8 isConnected();
7373
uint8 pending();
74+
75+
protected:
76+
static bool _hasBegun;
7477
};
7578

7679
#ifdef SERIAL_USB

STM32F1/cores/maple/wirish_time.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,15 @@
3232

3333
#include <libmaple/libmaple_types.h>
3434
#include <libmaple/delay.h>
35+
#include "Arduino.h"
3536

3637
void delay(unsigned long ms) {
3738
uint32 start = millis();
38-
while (millis() - start < ms)
39-
;
39+
do
40+
{
41+
yield();
42+
}
43+
while (millis() - start < ms);
4044
}
4145

4246
void delayMicroseconds(uint32 us) {

STM32F1/libraries/Adafruit_ILI9341_STM/Adafruit_ILI9341_STM.cpp

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Adafruit_ILI9341_STM::Adafruit_ILI9341_STM(int8_t cs, int8_t dc, int8_t rst) : A
3636
}
3737

3838

39-
void Adafruit_ILI9341_STM::spiwrite(uint8_t c) {
39+
void Adafruit_ILI9341_STM::spiwrite(uint16_t c) {
4040

4141
//Serial.print("0x"); Serial.print(c, HEX); Serial.print(", ");
4242

@@ -178,10 +178,7 @@ void Adafruit_ILI9341_STM::begin(void) {
178178
SPI.setBitOrder(MSBFIRST);
179179
SPI.setDataMode(SPI_MODE0);
180180
#elif defined (__STM32F1__)
181-
SPI.begin();
182-
SPI.setClockDivider(SPI_CLOCK_DIV2);
183-
SPI.setBitOrder(MSBFIRST);
184-
SPI.setDataMode(SPI_MODE0);
181+
SPI.beginTransaction(SPISettings(36000000));
185182

186183
#elif defined (__arm__)
187184
SPI.begin();
@@ -335,6 +332,7 @@ void Adafruit_ILI9341_STM::begin(void) {
335332
if (hwSPI) spi_begin();
336333
writecommand(ILI9341_DISPON); //Display on
337334
if (hwSPI) spi_end();
335+
if (hwSPI) SPI.setDataSize(SPI_CR1_DFF);
338336

339337
}
340338

@@ -345,18 +343,14 @@ void Adafruit_ILI9341_STM::setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1,
345343
writecommand(ILI9341_CASET); // Column addr set
346344
*dcport |= dcpinmask;
347345
*csport &= ~cspinmask;
348-
SPI.setDataSize (SPI_CR1_DFF);
349346
SPI.write(x0);
350347
SPI.write(x1);
351-
// SPI.setDataSize (0);
352348

353349
writecommand(ILI9341_PASET); // Row addr set
354350
*dcport |= dcpinmask;
355351
*csport &= ~cspinmask;
356-
// SPI.setDataSize (SPI_CR1_DFF);
357352
SPI.write(y0);
358353
SPI.write(y1);
359-
SPI.setDataSize (0);
360354

361355
writecommand(ILI9341_RAMWR); // write to RAM
362356

@@ -385,7 +379,6 @@ void Adafruit_ILI9341_STM::pushColor(uint16_t color) {
385379
//digitalWrite(_cs, LOW);
386380
*csport &= ~cspinmask;
387381

388-
spiwrite(color >> 8);
389382
spiwrite(color);
390383

391384
*csport |= cspinmask;
@@ -403,7 +396,6 @@ void Adafruit_ILI9341_STM::drawPixel(int16_t x, int16_t y, uint16_t color) {
403396
*dcport |= dcpinmask;
404397
*csport &= ~cspinmask;
405398

406-
spiwrite(color >> 8);
407399
spiwrite(color);
408400

409401
*csport |= cspinmask;
@@ -431,10 +423,8 @@ void Adafruit_ILI9341_STM::drawFastVLine(int16_t x, int16_t y, int16_t h,
431423
*csport &= ~cspinmask;
432424

433425
#if defined (__STM32F1__)
434-
SPI.setDataSize (SPI_CR1_DFF); // Set SPI 16bit mode
435426
lineBuffer[0] = color;
436427
SPI.dmaSend(lineBuffer, h, 0);
437-
SPI.setDataSize (0);
438428
#else
439429
uint8_t hi = color >> 8, lo = color;
440430
while (h--) {
@@ -464,10 +454,8 @@ void Adafruit_ILI9341_STM::drawFastHLine(int16_t x, int16_t y, int16_t w,
464454
*csport &= ~cspinmask;
465455

466456
#if defined (__STM32F1__)
467-
SPI.setDataSize (SPI_CR1_DFF); // Set spi 16bit mode
468457
lineBuffer[0] = color;
469458
SPI.dmaSend(lineBuffer, w, 0);
470-
SPI.setDataSize (0);
471459
#else
472460
uint8_t hi = color >> 8, lo = color;
473461
while (w--) {
@@ -485,11 +473,9 @@ void Adafruit_ILI9341_STM::fillScreen(uint16_t color) {
485473
setAddrWindow(0, 0, _width - 1, _height - 1);
486474
*dcport |= dcpinmask;
487475
*csport &= ~cspinmask;
488-
SPI.setDataSize (SPI_CR1_DFF); // Set spi 16bit mode
489476
lineBuffer[0] = color;
490477
SPI.dmaSend(lineBuffer, (65535), 0);
491478
SPI.dmaSend(lineBuffer, ((_width * _height) - 65535), 0);
492-
SPI.setDataSize (0);
493479

494480
#else
495481
fillRect(0, 0, _width, _height, color);
@@ -515,7 +501,6 @@ void Adafruit_ILI9341_STM::fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
515501
*dcport |= dcpinmask;
516502
*csport &= ~cspinmask;
517503
#if defined (__STM32F1__)
518-
SPI.setDataSize (SPI_CR1_DFF); // Set spi 16bit mode
519504
lineBuffer[0] = color;
520505
if (w*h <= 65535) {
521506
SPI.dmaSend(lineBuffer, (w*h), 0);
@@ -524,7 +509,6 @@ void Adafruit_ILI9341_STM::fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
524509
SPI.dmaSend(lineBuffer, (65535), 0);
525510
SPI.dmaSend(lineBuffer, ((w*h) - 65535), 0);
526511
}
527-
SPI.setDataSize (0);
528512
#else
529513
uint8_t hi = color >> 8, lo = color;
530514
for(y=h; y>0; y--)
@@ -672,6 +656,7 @@ uint16_t Adafruit_ILI9341_STM::color565(uint8_t r, uint8_t g, uint8_t b) {
672656
void Adafruit_ILI9341_STM::setRotation(uint8_t m) {
673657

674658
if (hwSPI) spi_begin();
659+
if (hwSPI) SPI.setDataSize(0);
675660
writecommand(ILI9341_MADCTL);
676661
rotation = m % 4; // can't be higher than 3
677662
switch (rotation) {
@@ -696,6 +681,7 @@ void Adafruit_ILI9341_STM::setRotation(uint8_t m) {
696681
_height = ILI9341_TFTWIDTH;
697682
break;
698683
}
684+
if (hwSPI) SPI.setDataSize(SPI_CR1_DFF);
699685
if (hwSPI) spi_end();
700686
}
701687

STM32F1/libraries/Adafruit_ILI9341_STM/Adafruit_ILI9341_STM.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ This library has been modified for the Maple Mini
1111
#include <Adafruit_GFX_AS.h>
1212
#include <avr/pgmspace.h>
1313

14+
#ifndef swap
15+
#define swap(a, b) { int16_t t = a; a = b; b = t; }
16+
#endif
17+
1418
#define ILI9341_TFTWIDTH 240
1519
#define ILI9341_TFTHEIGHT 320
1620

@@ -125,7 +129,7 @@ class Adafruit_ILI9341_STM : public Adafruit_GFX {
125129
void dummyclock(void);
126130
*/
127131

128-
void spiwrite(uint8_t),
132+
void spiwrite(uint16_t),
129133
writecommand(uint8_t c),
130134
writedata(uint8_t d),
131135
commandList(uint8_t *addr);

0 commit comments

Comments
 (0)