Merge remote-tracking branch 'upstream/master' into Fix-ifSerial
This commit is contained in:
commit
ef60992e20
|
@ -7,3 +7,5 @@ other/maple-bootloader/build
|
||||||
other/maple-bootloader/*~
|
other/maple-bootloader/*~
|
||||||
*.o
|
*.o
|
||||||
tools/src/stm32flash_serial/src/parsers/parsers.a
|
tools/src/stm32flash_serial/src/parsers/parsers.a
|
||||||
|
*.bak
|
||||||
|
*.1
|
||||||
|
|
|
@ -193,7 +193,8 @@ size_t HardwareSerial::write(unsigned char ch) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* edogaldo: Waits for the transmission of outgoing serial data to complete (Arduino 1.0 api specs) */
|
||||||
void HardwareSerial::flush(void) {
|
void HardwareSerial::flush(void) {
|
||||||
usart_reset_rx(this->usart_device);
|
while(!rb_is_empty(this->usart_device->wb)); // wait for TX buffer empty
|
||||||
usart_reset_tx(this->usart_device);
|
while(!((this->usart_device->regs->SR) & (1<<USART_SR_TC_BIT))); // wait for TC (Transmission Complete) flag set
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,8 +120,12 @@ extern char* ltoa( long value, char *string, int radix )
|
||||||
|
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
#if __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ > 9 || \
|
||||||
|
(__GNUC_MINOR__ == 9 && __GNUC_PATCHLEVEL__ > 2)))
|
||||||
|
extern char* utoa( unsigned value, char *string, int radix )
|
||||||
|
#else
|
||||||
extern char* utoa( unsigned long value, char *string, int radix )
|
extern char* utoa( unsigned long value, char *string, int radix )
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
return ultoa( value, string, radix ) ;
|
return ultoa( value, string, radix ) ;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,12 @@ extern void itoa( int n, char s[] ) ;
|
||||||
|
|
||||||
extern char* itoa( int value, char *string, int radix ) ;
|
extern char* itoa( int value, char *string, int radix ) ;
|
||||||
extern char* ltoa( long value, char *string, int radix ) ;
|
extern char* ltoa( long value, char *string, int radix ) ;
|
||||||
|
#if __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ > 9 || \
|
||||||
|
(__GNUC_MINOR__ == 9 && __GNUC_PATCHLEVEL__ > 2)))
|
||||||
|
extern char* utoa( unsigned value, char *string, int radix ) ;
|
||||||
|
#else
|
||||||
extern char* utoa( unsigned long value, char *string, int radix ) ;
|
extern char* utoa( unsigned long value, char *string, int radix ) ;
|
||||||
|
#endif
|
||||||
extern char* ultoa( unsigned long value, char *string, int radix ) ;
|
extern char* ultoa( unsigned long value, char *string, int radix ) ;
|
||||||
#endif /* 0 */
|
#endif /* 0 */
|
||||||
|
|
||||||
|
|
|
@ -341,7 +341,6 @@ void dma_set_per_addr(dma_dev *dev, dma_channel channel, __io void *addr) {
|
||||||
* @see dma_attach_interrupt()
|
* @see dma_attach_interrupt()
|
||||||
* @see dma_enable()
|
* @see dma_enable()
|
||||||
*/
|
*/
|
||||||
__deprecated
|
|
||||||
void dma_setup_transfer(dma_dev *dev,
|
void dma_setup_transfer(dma_dev *dev,
|
||||||
dma_channel channel,
|
dma_channel channel,
|
||||||
__io void *peripheral_address,
|
__io void *peripheral_address,
|
||||||
|
|
|
@ -142,7 +142,6 @@ gpio_pin_mode gpio_get_mode(gpio_dev *dev, uint8 pin) {
|
||||||
gpio_reg_map *regs = dev->regs;
|
gpio_reg_map *regs = dev->regs;
|
||||||
__io uint32 *cr = ®s->CRL + (pin >> 3);
|
__io uint32 *cr = ®s->CRL + (pin >> 3);
|
||||||
uint32 shift = (pin & 0x7) * 4;
|
uint32 shift = (pin & 0x7) * 4;
|
||||||
uint32 tmp = *cr;
|
|
||||||
|
|
||||||
uint32 crMode = (*cr>>shift) & 0x0F;
|
uint32 crMode = (*cr>>shift) & 0x0F;
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,7 @@ void spi_slave_enable(spi_dev *dev, spi_mode mode, uint32 flags) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Nonblocking SPI transmit.
|
* @brief Blocking SPI transmit.
|
||||||
* @param dev SPI port to use for transmission
|
* @param dev SPI port to use for transmission
|
||||||
* @param buf Buffer to transmit. The sizeof buf's elements are
|
* @param buf Buffer to transmit. The sizeof buf's elements are
|
||||||
* inferred from dev's data frame format (i.e., are
|
* 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) {
|
||||||
* @return Number of elements transmitted.
|
* @return Number of elements transmitted.
|
||||||
*/
|
*/
|
||||||
uint32 spi_tx(spi_dev *dev, const void *buf, uint32 len) {
|
uint32 spi_tx(spi_dev *dev, const void *buf, uint32 len) {
|
||||||
uint32 txed = 0;
|
uint32 txed = len;
|
||||||
uint8 byte_frame = spi_dff(dev) == SPI_DFF_8_BIT;
|
spi_reg_map *regs = dev->regs;
|
||||||
while (spi_is_tx_empty(dev) && (txed < len)) {
|
if ( spi_dff(dev) == SPI_DFF_8_BIT ) {
|
||||||
if (byte_frame) {
|
const uint8 * dp8 = (const uint8*)buf;
|
||||||
dev->regs->DR = ((const uint8*)buf)[txed++];
|
while ( len-- ) {
|
||||||
} else {
|
while ( (regs->SR & SPI_SR_TXE)==0 ) ; //while ( spi_is_tx_empty(dev)==0 ); // wait Tx to be empty
|
||||||
dev->regs->DR = ((const uint16*)buf)[txed++];
|
regs->DR = *dp8++;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
const uint16 * dp16 = (const uint16*)buf;
|
||||||
|
while ( len-- ) {
|
||||||
|
while ( (regs->SR & SPI_SR_TXE)==0 ) ; //while ( spi_is_tx_empty(dev)==0 ); // wait Tx to be empty
|
||||||
|
regs->DR = *dp16++;
|
||||||
|
}
|
||||||
|
}
|
||||||
return txed;
|
return txed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,9 @@ static void ifaceSetupHook(unsigned, void*);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define USB_TIMEOUT 50
|
#define USB_TIMEOUT 50
|
||||||
|
#if BOARD_HAVE_SERIALUSB
|
||||||
|
bool USBSerial::_hasBegun = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
USBSerial::USBSerial(void) {
|
USBSerial::USBSerial(void) {
|
||||||
#if !BOARD_HAVE_SERIALUSB
|
#if !BOARD_HAVE_SERIALUSB
|
||||||
|
@ -62,7 +65,12 @@ USBSerial::USBSerial(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void USBSerial::begin(void) {
|
void USBSerial::begin(void) {
|
||||||
|
|
||||||
#if BOARD_HAVE_SERIALUSB
|
#if BOARD_HAVE_SERIALUSB
|
||||||
|
if (_hasBegun)
|
||||||
|
return;
|
||||||
|
_hasBegun = true;
|
||||||
|
|
||||||
usb_cdcacm_enable(BOARD_USB_DISC_DEV, BOARD_USB_DISC_BIT);
|
usb_cdcacm_enable(BOARD_USB_DISC_DEV, BOARD_USB_DISC_BIT);
|
||||||
usb_cdcacm_set_hooks(USB_CDCACM_HOOK_RX, rxHook);
|
usb_cdcacm_set_hooks(USB_CDCACM_HOOK_RX, rxHook);
|
||||||
usb_cdcacm_set_hooks(USB_CDCACM_HOOK_IFACE_SETUP, ifaceSetupHook);
|
usb_cdcacm_set_hooks(USB_CDCACM_HOOK_IFACE_SETUP, ifaceSetupHook);
|
||||||
|
@ -75,6 +83,7 @@ void USBSerial::begin(unsigned long ignoreBaud)
|
||||||
volatile unsigned long removeCompilerWarningsIgnoreBaud=ignoreBaud;
|
volatile unsigned long removeCompilerWarningsIgnoreBaud=ignoreBaud;
|
||||||
|
|
||||||
ignoreBaud=removeCompilerWarningsIgnoreBaud;
|
ignoreBaud=removeCompilerWarningsIgnoreBaud;
|
||||||
|
begin();
|
||||||
}
|
}
|
||||||
void USBSerial::begin(unsigned long ignoreBaud, uint8_t ignore)
|
void USBSerial::begin(unsigned long ignoreBaud, uint8_t ignore)
|
||||||
{
|
{
|
||||||
|
@ -83,13 +92,16 @@ volatile uint8_t removeCompilerWarningsIgnore=ignore;
|
||||||
|
|
||||||
ignoreBaud=removeCompilerWarningsIgnoreBaud;
|
ignoreBaud=removeCompilerWarningsIgnoreBaud;
|
||||||
ignore=removeCompilerWarningsIgnore;
|
ignore=removeCompilerWarningsIgnore;
|
||||||
|
begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
void USBSerial::end(void) {
|
void USBSerial::end(void) {
|
||||||
#if BOARD_HAVE_SERIALUSB
|
#if BOARD_HAVE_SERIALUSB
|
||||||
usb_cdcacm_disable(BOARD_USB_DISC_DEV, BOARD_USB_DISC_BIT);
|
usb_cdcacm_disable(BOARD_USB_DISC_DEV, BOARD_USB_DISC_BIT);
|
||||||
usb_cdcacm_remove_hooks(USB_CDCACM_HOOK_RX | USB_CDCACM_HOOK_IFACE_SETUP);
|
usb_cdcacm_remove_hooks(USB_CDCACM_HOOK_RX | USB_CDCACM_HOOK_IFACE_SETUP);
|
||||||
|
_hasBegun = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t USBSerial::write(uint8 ch) {
|
size_t USBSerial::write(uint8 ch) {
|
||||||
|
|
|
@ -81,6 +81,9 @@ public:
|
||||||
* Deprecated, use the above.
|
* Deprecated, use the above.
|
||||||
*/
|
*/
|
||||||
uint8 isConnected() __attribute__((deprecated("Use !Serial instead"))) { return (bool) *this; }
|
uint8 isConnected() __attribute__((deprecated("Use !Serial instead"))) { return (bool) *this; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
static bool _hasBegun;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef SERIAL_USB
|
#ifdef SERIAL_USB
|
||||||
|
|
|
@ -32,11 +32,15 @@
|
||||||
|
|
||||||
#include <libmaple/libmaple_types.h>
|
#include <libmaple/libmaple_types.h>
|
||||||
#include <libmaple/delay.h>
|
#include <libmaple/delay.h>
|
||||||
|
#include "Arduino.h"
|
||||||
|
|
||||||
void delay(unsigned long ms) {
|
void delay(unsigned long ms) {
|
||||||
uint32 start = millis();
|
uint32 start = millis();
|
||||||
while (millis() - start < ms)
|
do
|
||||||
;
|
{
|
||||||
|
yield();
|
||||||
|
}
|
||||||
|
while (millis() - start < ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
void delayMicroseconds(uint32 us) {
|
void delayMicroseconds(uint32 us) {
|
||||||
|
|
|
@ -36,7 +36,7 @@ Adafruit_ILI9341_STM::Adafruit_ILI9341_STM(int8_t cs, int8_t dc, int8_t rst) : A
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Adafruit_ILI9341_STM::spiwrite(uint8_t c) {
|
void Adafruit_ILI9341_STM::spiwrite(uint16_t c) {
|
||||||
|
|
||||||
//Serial.print("0x"); Serial.print(c, HEX); Serial.print(", ");
|
//Serial.print("0x"); Serial.print(c, HEX); Serial.print(", ");
|
||||||
|
|
||||||
|
@ -178,10 +178,7 @@ void Adafruit_ILI9341_STM::begin(void) {
|
||||||
SPI.setBitOrder(MSBFIRST);
|
SPI.setBitOrder(MSBFIRST);
|
||||||
SPI.setDataMode(SPI_MODE0);
|
SPI.setDataMode(SPI_MODE0);
|
||||||
#elif defined (__STM32F1__)
|
#elif defined (__STM32F1__)
|
||||||
SPI.begin();
|
SPI.beginTransaction(SPISettings(36000000));
|
||||||
SPI.setClockDivider(SPI_CLOCK_DIV2);
|
|
||||||
SPI.setBitOrder(MSBFIRST);
|
|
||||||
SPI.setDataMode(SPI_MODE0);
|
|
||||||
|
|
||||||
#elif defined (__arm__)
|
#elif defined (__arm__)
|
||||||
SPI.begin();
|
SPI.begin();
|
||||||
|
@ -335,6 +332,7 @@ void Adafruit_ILI9341_STM::begin(void) {
|
||||||
if (hwSPI) spi_begin();
|
if (hwSPI) spi_begin();
|
||||||
writecommand(ILI9341_DISPON); //Display on
|
writecommand(ILI9341_DISPON); //Display on
|
||||||
if (hwSPI) spi_end();
|
if (hwSPI) spi_end();
|
||||||
|
if (hwSPI) SPI.setDataSize(SPI_CR1_DFF);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -345,18 +343,14 @@ void Adafruit_ILI9341_STM::setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1,
|
||||||
writecommand(ILI9341_CASET); // Column addr set
|
writecommand(ILI9341_CASET); // Column addr set
|
||||||
*dcport |= dcpinmask;
|
*dcport |= dcpinmask;
|
||||||
*csport &= ~cspinmask;
|
*csport &= ~cspinmask;
|
||||||
SPI.setDataSize (SPI_CR1_DFF);
|
|
||||||
SPI.write(x0);
|
SPI.write(x0);
|
||||||
SPI.write(x1);
|
SPI.write(x1);
|
||||||
// SPI.setDataSize (0);
|
|
||||||
|
|
||||||
writecommand(ILI9341_PASET); // Row addr set
|
writecommand(ILI9341_PASET); // Row addr set
|
||||||
*dcport |= dcpinmask;
|
*dcport |= dcpinmask;
|
||||||
*csport &= ~cspinmask;
|
*csport &= ~cspinmask;
|
||||||
// SPI.setDataSize (SPI_CR1_DFF);
|
|
||||||
SPI.write(y0);
|
SPI.write(y0);
|
||||||
SPI.write(y1);
|
SPI.write(y1);
|
||||||
SPI.setDataSize (0);
|
|
||||||
|
|
||||||
writecommand(ILI9341_RAMWR); // write to RAM
|
writecommand(ILI9341_RAMWR); // write to RAM
|
||||||
|
|
||||||
|
@ -385,7 +379,6 @@ void Adafruit_ILI9341_STM::pushColor(uint16_t color) {
|
||||||
//digitalWrite(_cs, LOW);
|
//digitalWrite(_cs, LOW);
|
||||||
*csport &= ~cspinmask;
|
*csport &= ~cspinmask;
|
||||||
|
|
||||||
spiwrite(color >> 8);
|
|
||||||
spiwrite(color);
|
spiwrite(color);
|
||||||
|
|
||||||
*csport |= cspinmask;
|
*csport |= cspinmask;
|
||||||
|
@ -403,7 +396,6 @@ void Adafruit_ILI9341_STM::drawPixel(int16_t x, int16_t y, uint16_t color) {
|
||||||
*dcport |= dcpinmask;
|
*dcport |= dcpinmask;
|
||||||
*csport &= ~cspinmask;
|
*csport &= ~cspinmask;
|
||||||
|
|
||||||
spiwrite(color >> 8);
|
|
||||||
spiwrite(color);
|
spiwrite(color);
|
||||||
|
|
||||||
*csport |= cspinmask;
|
*csport |= cspinmask;
|
||||||
|
@ -431,10 +423,8 @@ void Adafruit_ILI9341_STM::drawFastVLine(int16_t x, int16_t y, int16_t h,
|
||||||
*csport &= ~cspinmask;
|
*csport &= ~cspinmask;
|
||||||
|
|
||||||
#if defined (__STM32F1__)
|
#if defined (__STM32F1__)
|
||||||
SPI.setDataSize (SPI_CR1_DFF); // Set SPI 16bit mode
|
|
||||||
lineBuffer[0] = color;
|
lineBuffer[0] = color;
|
||||||
SPI.dmaSend(lineBuffer, h, 0);
|
SPI.dmaSend(lineBuffer, h, 0);
|
||||||
SPI.setDataSize (0);
|
|
||||||
#else
|
#else
|
||||||
uint8_t hi = color >> 8, lo = color;
|
uint8_t hi = color >> 8, lo = color;
|
||||||
while (h--) {
|
while (h--) {
|
||||||
|
@ -464,10 +454,8 @@ void Adafruit_ILI9341_STM::drawFastHLine(int16_t x, int16_t y, int16_t w,
|
||||||
*csport &= ~cspinmask;
|
*csport &= ~cspinmask;
|
||||||
|
|
||||||
#if defined (__STM32F1__)
|
#if defined (__STM32F1__)
|
||||||
SPI.setDataSize (SPI_CR1_DFF); // Set spi 16bit mode
|
|
||||||
lineBuffer[0] = color;
|
lineBuffer[0] = color;
|
||||||
SPI.dmaSend(lineBuffer, w, 0);
|
SPI.dmaSend(lineBuffer, w, 0);
|
||||||
SPI.setDataSize (0);
|
|
||||||
#else
|
#else
|
||||||
uint8_t hi = color >> 8, lo = color;
|
uint8_t hi = color >> 8, lo = color;
|
||||||
while (w--) {
|
while (w--) {
|
||||||
|
@ -485,11 +473,9 @@ void Adafruit_ILI9341_STM::fillScreen(uint16_t color) {
|
||||||
setAddrWindow(0, 0, _width - 1, _height - 1);
|
setAddrWindow(0, 0, _width - 1, _height - 1);
|
||||||
*dcport |= dcpinmask;
|
*dcport |= dcpinmask;
|
||||||
*csport &= ~cspinmask;
|
*csport &= ~cspinmask;
|
||||||
SPI.setDataSize (SPI_CR1_DFF); // Set spi 16bit mode
|
|
||||||
lineBuffer[0] = color;
|
lineBuffer[0] = color;
|
||||||
SPI.dmaSend(lineBuffer, (65535), 0);
|
SPI.dmaSend(lineBuffer, (65535), 0);
|
||||||
SPI.dmaSend(lineBuffer, ((_width * _height) - 65535), 0);
|
SPI.dmaSend(lineBuffer, ((_width * _height) - 65535), 0);
|
||||||
SPI.setDataSize (0);
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
fillRect(0, 0, _width, _height, color);
|
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,
|
||||||
*dcport |= dcpinmask;
|
*dcport |= dcpinmask;
|
||||||
*csport &= ~cspinmask;
|
*csport &= ~cspinmask;
|
||||||
#if defined (__STM32F1__)
|
#if defined (__STM32F1__)
|
||||||
SPI.setDataSize (SPI_CR1_DFF); // Set spi 16bit mode
|
|
||||||
lineBuffer[0] = color;
|
lineBuffer[0] = color;
|
||||||
if (w*h <= 65535) {
|
if (w*h <= 65535) {
|
||||||
SPI.dmaSend(lineBuffer, (w*h), 0);
|
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,
|
||||||
SPI.dmaSend(lineBuffer, (65535), 0);
|
SPI.dmaSend(lineBuffer, (65535), 0);
|
||||||
SPI.dmaSend(lineBuffer, ((w*h) - 65535), 0);
|
SPI.dmaSend(lineBuffer, ((w*h) - 65535), 0);
|
||||||
}
|
}
|
||||||
SPI.setDataSize (0);
|
|
||||||
#else
|
#else
|
||||||
uint8_t hi = color >> 8, lo = color;
|
uint8_t hi = color >> 8, lo = color;
|
||||||
for(y=h; y>0; y--)
|
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) {
|
||||||
void Adafruit_ILI9341_STM::setRotation(uint8_t m) {
|
void Adafruit_ILI9341_STM::setRotation(uint8_t m) {
|
||||||
|
|
||||||
if (hwSPI) spi_begin();
|
if (hwSPI) spi_begin();
|
||||||
|
if (hwSPI) SPI.setDataSize(0);
|
||||||
writecommand(ILI9341_MADCTL);
|
writecommand(ILI9341_MADCTL);
|
||||||
rotation = m % 4; // can't be higher than 3
|
rotation = m % 4; // can't be higher than 3
|
||||||
switch (rotation) {
|
switch (rotation) {
|
||||||
|
@ -696,6 +681,7 @@ void Adafruit_ILI9341_STM::setRotation(uint8_t m) {
|
||||||
_height = ILI9341_TFTWIDTH;
|
_height = ILI9341_TFTWIDTH;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (hwSPI) SPI.setDataSize(SPI_CR1_DFF);
|
||||||
if (hwSPI) spi_end();
|
if (hwSPI) spi_end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,10 @@ This library has been modified for the Maple Mini
|
||||||
#include <Adafruit_GFX_AS.h>
|
#include <Adafruit_GFX_AS.h>
|
||||||
#include <avr/pgmspace.h>
|
#include <avr/pgmspace.h>
|
||||||
|
|
||||||
|
#ifndef swap
|
||||||
|
#define swap(a, b) { int16_t t = a; a = b; b = t; }
|
||||||
|
#endif
|
||||||
|
|
||||||
#define ILI9341_TFTWIDTH 240
|
#define ILI9341_TFTWIDTH 240
|
||||||
#define ILI9341_TFTHEIGHT 320
|
#define ILI9341_TFTHEIGHT 320
|
||||||
|
|
||||||
|
@ -125,7 +129,7 @@ class Adafruit_ILI9341_STM : public Adafruit_GFX {
|
||||||
void dummyclock(void);
|
void dummyclock(void);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void spiwrite(uint8_t),
|
void spiwrite(uint16_t),
|
||||||
writecommand(uint8_t c),
|
writecommand(uint8_t c),
|
||||||
writedata(uint8_t d),
|
writedata(uint8_t d),
|
||||||
commandList(uint8_t *addr);
|
commandList(uint8_t *addr);
|
||||||
|
|
|
@ -521,6 +521,28 @@ uint16 EEPROMClass::write(uint16 Address, uint16 Data)
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Writes/upadtes variable data in EEPROM.
|
||||||
|
The value is written only if differs from the one already saved at the same address.
|
||||||
|
* @param VirtAddress: Variable virtual address
|
||||||
|
* @param Data: 16 bit data to be written
|
||||||
|
* @retval Success or error status:
|
||||||
|
* - EEPROM_SAME_VALUE: If new Data matches existing EEPROM Data
|
||||||
|
* - FLASH_COMPLETE: on success
|
||||||
|
* - EEPROM_BAD_ADDRESS: if address = 0xFFFF
|
||||||
|
* - EEPROM_PAGE_FULL: if valid page is full
|
||||||
|
* - EEPROM_NO_VALID_PAGE: if no valid page was found
|
||||||
|
* - EEPROM_OUT_SIZE: if no empty EEPROM variables
|
||||||
|
* - Flash error code: on write Flash error
|
||||||
|
*/
|
||||||
|
uint16 EEPROMClass::update(uint16 Address, uint16 Data)
|
||||||
|
{
|
||||||
|
if (read(Address) == Data)
|
||||||
|
return EEPROM_SAME_VALUE;
|
||||||
|
else
|
||||||
|
return write(Address, Data);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return number of variable
|
* @brief Return number of variable
|
||||||
* @retval Number of variables
|
* @retval Number of variables
|
||||||
|
|
|
@ -47,6 +47,7 @@ enum : uint16
|
||||||
EEPROM_BAD_ADDRESS = ((uint16)0x0082),
|
EEPROM_BAD_ADDRESS = ((uint16)0x0082),
|
||||||
EEPROM_BAD_FLASH = ((uint16)0x0083),
|
EEPROM_BAD_FLASH = ((uint16)0x0083),
|
||||||
EEPROM_NOT_INIT = ((uint16)0x0084),
|
EEPROM_NOT_INIT = ((uint16)0x0084),
|
||||||
|
EEPROM_SAME_VALUE = ((uint16)0x0085),
|
||||||
EEPROM_NO_VALID_PAGE = ((uint16)0x00AB)
|
EEPROM_NO_VALID_PAGE = ((uint16)0x00AB)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -67,6 +68,7 @@ public:
|
||||||
uint16 read (uint16 address);
|
uint16 read (uint16 address);
|
||||||
uint16 read (uint16 address, uint16 *data);
|
uint16 read (uint16 address, uint16 *data);
|
||||||
uint16 write(uint16 address, uint16 data);
|
uint16 write(uint16 address, uint16 data);
|
||||||
|
uint16 update(uint16 address, uint16 data);
|
||||||
uint16 count(uint16 *);
|
uint16 count(uint16 *);
|
||||||
uint16 maxcount(void);
|
uint16 maxcount(void);
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,8 @@
|
||||||
#include "boards.h"
|
#include "boards.h"
|
||||||
|
|
||||||
//#include "HardwareSerial.h"
|
//#include "HardwareSerial.h"
|
||||||
|
/** Time in ms for DMA receive timeout */
|
||||||
|
#define DMA_TIMEOUT 100
|
||||||
|
|
||||||
#if CYCLES_PER_MICROSECOND != 72
|
#if CYCLES_PER_MICROSECOND != 72
|
||||||
/* TODO [0.2.0?] something smarter than this */
|
/* TODO [0.2.0?] something smarter than this */
|
||||||
|
@ -135,7 +137,6 @@ SPIClass::SPIClass(uint32 spi_num) {
|
||||||
_settings[2].spiRxDmaChannel = DMA_CH1;
|
_settings[2].spiRxDmaChannel = DMA_CH1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//pinMode(BOARD_SPI_DEFAULT_SS,OUTPUT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -158,7 +159,7 @@ void SPIClass::begin(void) {
|
||||||
void SPIClass::beginSlave(void) {
|
void SPIClass::beginSlave(void) {
|
||||||
spi_init(_currentSetting->spi_d);
|
spi_init(_currentSetting->spi_d);
|
||||||
configure_gpios(_currentSetting->spi_d, 0);
|
configure_gpios(_currentSetting->spi_d, 0);
|
||||||
uint32 flags = ((_currentSetting->bitOrder == MSBFIRST ? SPI_FRAME_MSB : SPI_FRAME_LSB) | _currentSetting->dataSize | SPI_SW_SLAVE);
|
uint32 flags = ((_currentSetting->bitOrder == MSBFIRST ? SPI_FRAME_MSB : SPI_FRAME_LSB) | _currentSetting->dataSize | SPI_RX_ONLY);
|
||||||
#ifdef SPI_DEBUG
|
#ifdef SPI_DEBUG
|
||||||
Serial.print("spi_slave_enable("); Serial.print(_currentSetting->dataMode); Serial.print(","); Serial.print(flags); Serial.println(")");
|
Serial.print("spi_slave_enable("); Serial.print(_currentSetting->dataMode); Serial.print(","); Serial.print(flags); Serial.println(")");
|
||||||
#endif
|
#endif
|
||||||
|
@ -213,7 +214,9 @@ void SPIClass::setDataSize(uint32 datasize)
|
||||||
{
|
{
|
||||||
_currentSetting->dataSize = datasize;
|
_currentSetting->dataSize = datasize;
|
||||||
uint32 cr1 = _currentSetting->spi_d->regs->CR1 & ~(SPI_CR1_DFF);
|
uint32 cr1 = _currentSetting->spi_d->regs->CR1 & ~(SPI_CR1_DFF);
|
||||||
_currentSetting->spi_d->regs->CR1 = cr1 | (datasize & SPI_CR1_DFF);
|
uint8 en = spi_is_enabled(_currentSetting->spi_d);
|
||||||
|
spi_peripheral_disable(_currentSetting->spi_d);
|
||||||
|
_currentSetting->spi_d->regs->CR1 = cr1 | (datasize & SPI_CR1_DFF) | en;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SPIClass::setDataMode(uint8_t dataMode)
|
void SPIClass::setDataMode(uint8_t dataMode)
|
||||||
|
@ -256,9 +259,6 @@ void SPIClass::beginTransaction(uint8_t pin, SPISettings settings)
|
||||||
#ifdef SPI_DEBUG
|
#ifdef SPI_DEBUG
|
||||||
Serial.println("SPIClass::beginTransaction");
|
Serial.println("SPIClass::beginTransaction");
|
||||||
#endif
|
#endif
|
||||||
//_SSPin=pin;
|
|
||||||
//pinMode(_SSPin,OUTPUT);
|
|
||||||
//digitalWrite(_SSPin,LOW);
|
|
||||||
setBitOrder(settings.bitOrder);
|
setBitOrder(settings.bitOrder);
|
||||||
setDataMode(settings.dataMode);
|
setDataMode(settings.dataMode);
|
||||||
setDataSize(settings.dataSize);
|
setDataSize(settings.dataSize);
|
||||||
|
@ -304,138 +304,134 @@ void SPIClass::endTransaction(void)
|
||||||
* I/O
|
* I/O
|
||||||
*/
|
*/
|
||||||
|
|
||||||
uint8 SPIClass::read(void) {
|
uint16 SPIClass::read(void)
|
||||||
uint8 buf[1];
|
{
|
||||||
this->read(buf, 1);
|
while ( spi_is_rx_nonempty(_currentSetting->spi_d)==0 ) ;
|
||||||
return buf[0];
|
return (uint16)spi_rx_reg(_currentSetting->spi_d);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SPIClass::read(uint8 *buf, uint32 len) {
|
void SPIClass::read(uint8 *buf, uint32 len)
|
||||||
uint32 rxed = 0;
|
{
|
||||||
while (rxed < len) {
|
if ( len == 0 ) return;
|
||||||
while (!spi_is_rx_nonempty(_currentSetting->spi_d))
|
spi_rx_reg(_currentSetting->spi_d); // clear the RX buffer in case a byte is waiting on it.
|
||||||
;
|
spi_reg_map * regs = _currentSetting->spi_d->regs;
|
||||||
buf[rxed++] = (uint8)spi_rx_reg(_currentSetting->spi_d);
|
// start sequence: write byte 0
|
||||||
}
|
regs->DR = 0x00FF; // write the first byte
|
||||||
|
// main loop
|
||||||
|
while ( (--len) ) {
|
||||||
|
while( !(regs->SR & SPI_SR_TXE) ); // wait for TXE flag
|
||||||
|
noInterrupts(); // go atomic level - avoid interrupts to surely get the previously received data
|
||||||
|
regs->DR = 0x00FF; // write the next data item to be transmitted into the SPI_DR register. This clears the TXE flag.
|
||||||
|
while ( !(regs->SR & SPI_SR_RXNE) ); // wait till data is available in the DR register
|
||||||
|
*buf++ = (uint8)(regs->DR); // read and store the received byte. This clears the RXNE flag.
|
||||||
|
interrupts(); // let systick do its job
|
||||||
|
}
|
||||||
|
// read remaining last byte
|
||||||
|
while ( !(regs->SR & SPI_SR_RXNE) ); // wait till data is available in the Rx register
|
||||||
|
*buf++ = (uint8)(regs->DR); // read and store the received byte
|
||||||
}
|
}
|
||||||
|
|
||||||
void SPIClass::write(uint16 data) {
|
void SPIClass::write(uint16 data)
|
||||||
// this->write(&data, 1);
|
{
|
||||||
|
|
||||||
/* Added for 16bit data Victor Perez. Roger Clark
|
/* Added for 16bit data Victor Perez. Roger Clark
|
||||||
* Improved speed by just directly writing the single byte to the SPI data reg and wait for completion, * by taking the Tx code from transfer(byte)
|
* Improved speed by just directly writing the single byte to the SPI data reg and wait for completion,
|
||||||
* The original method, of calling write(*data, length) .
|
* by taking the Tx code from transfer(byte)
|
||||||
* This almost doubles the speed of this function.
|
* This almost doubles the speed of this function.
|
||||||
*/
|
*/
|
||||||
|
spi_tx_reg(_currentSetting->spi_d, data); // write the data to be transmitted into the SPI_DR register (this clears the TXE flag)
|
||||||
spi_tx_reg(_currentSetting->spi_d, data); // "2. Write the first data item to be transmitted into the SPI_DR register (this clears the TXE flag)."
|
|
||||||
while (spi_is_tx_empty(_currentSetting->spi_d) == 0); // "5. Wait until TXE=1 ..."
|
while (spi_is_tx_empty(_currentSetting->spi_d) == 0); // "5. Wait until TXE=1 ..."
|
||||||
while (spi_is_busy(_currentSetting->spi_d) != 0); // "... and then wait until BSY=0 before disabling the SPI."
|
while (spi_is_busy(_currentSetting->spi_d) != 0); // "... and then wait until BSY=0 before disabling the SPI."
|
||||||
}
|
}
|
||||||
|
|
||||||
//void SPIClass::write(uint8 byte) {
|
void SPIClass::write(uint16 data, uint32 n)
|
||||||
// this->write(&byte, 1);
|
{
|
||||||
|
// Added by stevstrong: Repeatedly send same data by the specified number of times
|
||||||
/* Roger Clark
|
spi_reg_map * regs = _currentSetting->spi_d->regs;
|
||||||
* Improved speed by just directly writing the single byte to the SPI data reg and wait for completion, * by taking the Tx code from transfer(byte)
|
while ( (n--)>0 ) {
|
||||||
* The original method, of calling write(*data, length) .
|
regs->DR = data; // write the data to be transmitted into the SPI_DR register (this clears the TXE flag)
|
||||||
* This almost doubles the speed of this function.
|
while ( (regs->SR & SPI_SR_TXE)==0 ) ; // wait till Tx empty
|
||||||
*/
|
|
||||||
|
|
||||||
// spi_tx_reg(_currentSetting->spi_d, byte); // "2. Write the first data item to be transmitted into the SPI_DR register (this clears the TXE flag)."
|
|
||||||
// while (spi_is_tx_empty(_currentSetting->spi_d) == 0); // "5. Wait until TXE=1 ..."
|
|
||||||
// while (spi_is_busy(_currentSetting->spi_d) != 0); // "... and then wait until BSY=0 before disabling the SPI."
|
|
||||||
//}
|
|
||||||
|
|
||||||
void SPIClass::write(const uint8 *data, uint32 length) {
|
|
||||||
uint32 txed = 0;
|
|
||||||
while (txed < length) {
|
|
||||||
txed += spi_tx(_currentSetting->spi_d, data + txed, length - txed);
|
|
||||||
}
|
|
||||||
while (spi_is_tx_empty(_currentSetting->spi_d) == 0); // "4. After writing the last data item into the SPI_DR register, wait until TXE=1 ..."
|
|
||||||
while (spi_is_busy(_currentSetting->spi_d) != 0); // "... then wait until BSY=0, this indicates that the transmission of the last data is complete."
|
|
||||||
// taken from SdSpiSTM32F1.cpp - Victor's lib, and adapted to support device selection
|
|
||||||
if (spi_is_rx_nonempty(_currentSetting->spi_d)) {
|
|
||||||
uint8_t b = spi_rx_reg(_currentSetting->spi_d);
|
|
||||||
}
|
}
|
||||||
|
while ( (regs->SR & SPI_SR_BSY) != 0); // wait until BSY=0 before returning
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t SPIClass::transfer16(uint16_t wr_data) const {
|
void SPIClass::write(void *data, uint32 length)
|
||||||
spi_tx_reg(_currentSetting->spi_d, wr_data); // "2. Write the first data item to be transmitted into the SPI_DR register (this clears the TXE flag)."
|
{
|
||||||
while (spi_is_rx_nonempty(_currentSetting->spi_d) == 0); // "4. Wait until RXNE=1 ..."
|
spi_dev * spi_d = _currentSetting->spi_d;
|
||||||
uint16_t rd_data = spi_rx_reg(_currentSetting->spi_d); // "... and read the last received data."
|
spi_tx(spi_d, (void*)data, length); // data can be array of bytes or words
|
||||||
// while (spi_is_tx_empty(_currentSetting->spi_d) == 0); // "5. Wait until TXE=1 ..."
|
while (spi_is_tx_empty(spi_d) == 0); // "5. Wait until TXE=1 ..."
|
||||||
// while (spi_is_busy(_currentSetting->spi_d) != 0); // "... and then wait until BSY=0 before disabling the SPI."
|
while (spi_is_busy(spi_d) != 0); // "... and then wait until BSY=0 before disabling the SPI."
|
||||||
return rd_data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8 SPIClass::transfer(uint8 byte) const {
|
uint8 SPIClass::transfer(uint8 byte) const
|
||||||
spi_tx_reg(_currentSetting->spi_d, byte); // "2. Write the first data item to be transmitted into the SPI_DR register (this clears the TXE flag)."
|
{
|
||||||
while (spi_is_rx_nonempty(_currentSetting->spi_d) == 0); // "4. Wait until RXNE=1 ..."
|
spi_dev * spi_d = _currentSetting->spi_d;
|
||||||
uint8 b = spi_rx_reg(_currentSetting->spi_d); // "... and read the last received data."
|
spi_rx_reg(spi_d); // read any previous data
|
||||||
while (spi_is_tx_empty(_currentSetting->spi_d) == 0); // "5. Wait until TXE=1 ..."
|
spi_tx_reg(spi_d, byte); // Write the data item to be transmitted into the SPI_DR register
|
||||||
while (spi_is_busy(_currentSetting->spi_d) != 0); // "... and then wait until BSY=0 before disabling the SPI."
|
while (spi_is_tx_empty(spi_d) == 0); // "5. Wait until TXE=1 ..."
|
||||||
return b;
|
while (spi_is_busy(spi_d) != 0); // "... and then wait until BSY=0 before disabling the SPI."
|
||||||
|
return (uint8)spi_rx_reg(spi_d); // "... and read the last received data."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint16_t SPIClass::transfer16(uint16_t wr_data) const
|
||||||
|
{
|
||||||
|
spi_dev * spi_d = _currentSetting->spi_d;
|
||||||
|
spi_rx_reg(spi_d); // read any previous data
|
||||||
|
spi_tx_reg(spi_d, wr_data); // "2. Write the first data item to be transmitted into the SPI_DR register (this clears the TXE flag)."
|
||||||
|
while (spi_is_tx_empty(spi_d) == 0); // "5. Wait until TXE=1 ..."
|
||||||
|
while (spi_is_busy(spi_d) != 0); // "... and then wait until BSY=0 before disabling the SPI."
|
||||||
|
return (uint16)spi_rx_reg(spi_d); // "... and read the last received data."
|
||||||
|
}
|
||||||
|
|
||||||
/* Roger Clark and Victor Perez, 2015
|
/* Roger Clark and Victor Perez, 2015
|
||||||
* Performs a DMA SPI transfer with at least a receive buffer.
|
* Performs a DMA SPI transfer with at least a receive buffer.
|
||||||
* If a TX buffer is not provided, FF is sent over and over for the lenght of the transfer.
|
* If a TX buffer is not provided, FF is sent over and over for the length of the transfer.
|
||||||
* On exit TX buffer is not modified, and RX buffer cotains the received data.
|
* On exit TX buffer is not modified, and RX buffer contains the received data.
|
||||||
* Still in progress.
|
* Still in progress.
|
||||||
*/
|
*/
|
||||||
uint8 SPIClass::dmaTransfer(uint8 *transmitBuf, uint8 *receiveBuf, uint16 length) {
|
uint8 SPIClass::dmaTransfer(void * transmitBuf, void * receiveBuf, uint16 length)
|
||||||
|
{
|
||||||
if (length == 0) return 0;
|
if (length == 0) return 0;
|
||||||
uint8 b = 0;
|
uint8 b = 0;
|
||||||
if (spi_is_rx_nonempty(_currentSetting->spi_d) == 1) b = spi_rx_reg(_currentSetting->spi_d); //Clear the RX buffer in case a byte is waiting on it.
|
|
||||||
// dma1_ch3_Active=true;
|
// dma1_ch3_Active=true;
|
||||||
dma_init(_currentSetting->spiDmaDev);
|
dma_init(_currentSetting->spiDmaDev);
|
||||||
// dma_attach_interrupt(DMA1, DMA_CH3, &SPIClass::DMA1_CH3_Event);
|
// dma_attach_interrupt(DMA1, DMA_CH3, &SPIClass::DMA1_CH3_Event);
|
||||||
|
|
||||||
// RX
|
// RX
|
||||||
spi_rx_dma_enable(_currentSetting->spi_d);
|
dma_xfer_size dma_bit_size = (_currentSetting->dataSize==DATA_SIZE_16BIT) ? DMA_SIZE_16BITS : DMA_SIZE_8BITS;
|
||||||
dma_setup_transfer(_currentSetting->spiDmaDev, _currentSetting->spiRxDmaChannel, &_currentSetting->spi_d->regs->DR, DMA_SIZE_8BITS,
|
dma_setup_transfer(_currentSetting->spiDmaDev, _currentSetting->spiRxDmaChannel, &_currentSetting->spi_d->regs->DR, dma_bit_size,
|
||||||
receiveBuf, DMA_SIZE_8BITS, (DMA_MINC_MODE | DMA_TRNS_CMPLT));// receive buffer DMA
|
receiveBuf, dma_bit_size, (DMA_MINC_MODE));// receive buffer DMA
|
||||||
dma_set_num_transfers(_currentSetting->spiDmaDev, _currentSetting->spiRxDmaChannel, length);
|
dma_set_num_transfers(_currentSetting->spiDmaDev, _currentSetting->spiRxDmaChannel, length);
|
||||||
|
dma_enable(_currentSetting->spiDmaDev, _currentSetting->spiRxDmaChannel);// enable receive
|
||||||
|
|
||||||
// TX
|
// TX
|
||||||
spi_tx_dma_enable(_currentSetting->spi_d);
|
uint32 flags = (DMA_MINC_MODE | DMA_FROM_MEM);
|
||||||
if (!transmitBuf) {
|
if ( transmitBuf==0 ) {
|
||||||
static uint8_t ff = 0XFF;
|
static uint8_t ff = 0XFF;
|
||||||
transmitBuf = &ff;
|
transmitBuf = &ff;
|
||||||
dma_setup_transfer(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, &_currentSetting->spi_d->regs->DR, DMA_SIZE_8BITS,
|
flags ^= DMA_MINC_MODE; // remove increment mode
|
||||||
transmitBuf, DMA_SIZE_8BITS, (DMA_FROM_MEM | DMA_TRNS_CMPLT));// Transmit FF repeatedly
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
dma_setup_transfer(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, &_currentSetting->spi_d->regs->DR, DMA_SIZE_8BITS,
|
|
||||||
transmitBuf, DMA_SIZE_8BITS, (DMA_MINC_MODE | DMA_FROM_MEM | DMA_TRNS_CMPLT));// Transmit buffer DMA
|
|
||||||
}
|
}
|
||||||
|
dma_setup_transfer(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, &_currentSetting->spi_d->regs->DR, dma_bit_size,
|
||||||
|
transmitBuf, dma_bit_size, flags);// Transmit buffer DMA
|
||||||
dma_set_num_transfers(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, length);
|
dma_set_num_transfers(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, length);
|
||||||
|
dma_clear_isr_bits(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);
|
||||||
dma_enable(_currentSetting->spiDmaDev, _currentSetting->spiRxDmaChannel);// enable receive
|
|
||||||
dma_enable(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);// enable transmit
|
dma_enable(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);// enable transmit
|
||||||
|
|
||||||
// while (dma1_ch3_Active);
|
spi_rx_reg(_currentSetting->spi_d); //Clear the RX buffer in case a byte is waiting on it.
|
||||||
// if (receiveBuf) {
|
spi_rx_dma_enable(_currentSetting->spi_d);
|
||||||
uint32_t m = millis();
|
spi_tx_dma_enable(_currentSetting->spi_d); // must be the last enable to avoid DMA error flag
|
||||||
while ((dma_get_isr_bits(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel) & 0x2)==0) {//Avoid interrupts and just loop waiting for the flag to be set.
|
|
||||||
if ((millis() - m) > 100) {
|
uint32_t m = millis();
|
||||||
// dma1_ch3_Active = 0;
|
while ((dma_get_isr_bits(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel) & DMA_ISR_TCIF1)==0) {//Avoid interrupts and just loop waiting for the flag to be set.
|
||||||
b = 2;
|
//delayMicroseconds(10);
|
||||||
break;
|
if ((millis() - m) > DMA_TIMEOUT) { b = 2; break; }
|
||||||
}
|
}
|
||||||
}
|
|
||||||
dma_clear_isr_bits(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);
|
|
||||||
|
|
||||||
// }
|
|
||||||
while (spi_is_tx_empty(_currentSetting->spi_d) == 0); // "5. Wait until TXE=1 ..."
|
while (spi_is_tx_empty(_currentSetting->spi_d) == 0); // "5. Wait until TXE=1 ..."
|
||||||
while (spi_is_busy(_currentSetting->spi_d) != 0); // "... and then wait until BSY=0 before disabling the SPI."
|
while (spi_is_busy(_currentSetting->spi_d) != 0); // "... and then wait until BSY=0 before disabling the SPI."
|
||||||
dma_disable(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);
|
|
||||||
dma_disable(_currentSetting->spiDmaDev, _currentSetting->spiRxDmaChannel);
|
|
||||||
spi_rx_dma_disable(_currentSetting->spi_d); // And disable generation of DMA request from the SPI port so other peripherals can use the channels
|
|
||||||
spi_tx_dma_disable(_currentSetting->spi_d);
|
spi_tx_dma_disable(_currentSetting->spi_d);
|
||||||
if (spi_is_rx_nonempty(_currentSetting->spi_d) != 0){; // "4. Wait until RXNE=1 ..."
|
spi_rx_dma_disable(_currentSetting->spi_d); // And disable generation of DMA request from the SPI port so other peripherals can use the channels
|
||||||
uint8 x = spi_rx_reg(_currentSetting->spi_d); // "... and read the last received data."
|
dma_disable(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);
|
||||||
}
|
dma_disable(_currentSetting->spiDmaDev, _currentSetting->spiRxDmaChannel);
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -443,66 +439,36 @@ uint8 SPIClass::dmaTransfer(uint8 *transmitBuf, uint8 *receiveBuf, uint16 length
|
||||||
* Performs a DMA SPI send using a TX buffer.
|
* Performs a DMA SPI send using a TX buffer.
|
||||||
* On exit TX buffer is not modified.
|
* On exit TX buffer is not modified.
|
||||||
* Still in progress.
|
* Still in progress.
|
||||||
|
* 2016 - stevstrong - reworked to automatically detect bit size from SPI setting
|
||||||
*/
|
*/
|
||||||
uint8 SPIClass::dmaSend(uint8 *transmitBuf, uint16 length, bool minc) {
|
uint8 SPIClass::dmaSend(void * transmitBuf, uint16 length, bool minc)
|
||||||
|
{
|
||||||
if (length == 0) return 0;
|
if (length == 0) return 0;
|
||||||
uint32 flags = ((DMA_MINC_MODE * minc) | DMA_FROM_MEM | DMA_TRNS_CMPLT);
|
uint32 flags = ( (DMA_MINC_MODE*minc) | DMA_FROM_MEM | DMA_TRNS_CMPLT);
|
||||||
uint8 b = 0;
|
uint8 b = 0;
|
||||||
// dma1_ch3_Active=true;
|
|
||||||
dma_init(_currentSetting->spiDmaDev);
|
dma_init(_currentSetting->spiDmaDev);
|
||||||
// dma_attach_interrupt(DMA1, DMA_CH3, &SPIClass::DMA1_CH3_Event);
|
|
||||||
|
|
||||||
// TX
|
// TX
|
||||||
spi_tx_dma_enable(_currentSetting->spi_d);
|
dma_xfer_size dma_bit_size = (_currentSetting->dataSize==DATA_SIZE_16BIT) ? DMA_SIZE_16BITS : DMA_SIZE_8BITS;
|
||||||
dma_setup_transfer(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, &_currentSetting->spi_d->regs->DR, DMA_SIZE_8BITS,
|
dma_setup_transfer(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, &_currentSetting->spi_d->regs->DR, dma_bit_size,
|
||||||
transmitBuf, DMA_SIZE_8BITS, flags);// Transmit buffer DMA
|
transmitBuf, dma_bit_size, flags);// Transmit buffer DMA
|
||||||
dma_set_num_transfers(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, length);
|
dma_set_num_transfers(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, length);
|
||||||
dma_enable(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);// enable transmit
|
|
||||||
|
|
||||||
// while (dma1_ch3_Active);
|
|
||||||
while ((dma_get_isr_bits(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel) & 0x2)==0); //Avoid interrupts and just loop waiting for the flag to be set.
|
|
||||||
dma_clear_isr_bits(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);
|
dma_clear_isr_bits(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);
|
||||||
|
dma_enable(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);// enable transmit
|
||||||
|
spi_tx_dma_enable(_currentSetting->spi_d);
|
||||||
|
|
||||||
|
uint32_t m = millis();
|
||||||
|
while ((dma_get_isr_bits(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel) & DMA_ISR_TCIF1)==0) {//Avoid interrupts and just loop waiting for the flag to be set.
|
||||||
|
//delayMicroseconds(10);
|
||||||
|
if ((millis() - m) > DMA_TIMEOUT) { b = 2; break; }
|
||||||
|
}
|
||||||
|
|
||||||
while (spi_is_tx_empty(_currentSetting->spi_d) == 0); // "5. Wait until TXE=1 ..."
|
while (spi_is_tx_empty(_currentSetting->spi_d) == 0); // "5. Wait until TXE=1 ..."
|
||||||
while (spi_is_busy(_currentSetting->spi_d) != 0); // "... and then wait until BSY=0 before disabling the SPI."
|
while (spi_is_busy(_currentSetting->spi_d) != 0); // "... and then wait until BSY=0 before disabling the SPI."
|
||||||
dma_disable(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);
|
|
||||||
spi_tx_dma_disable(_currentSetting->spi_d);
|
spi_tx_dma_disable(_currentSetting->spi_d);
|
||||||
if (spi_is_rx_nonempty(_currentSetting->spi_d) != 0){; // "4. Wait until RXNE=1 ..."
|
|
||||||
uint8 x = spi_rx_reg(_currentSetting->spi_d); // "... and read the last received data."
|
|
||||||
}
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8 SPIClass::dmaSend(uint16 *transmitBuf, uint16 length, bool minc) {
|
|
||||||
if (length == 0) return 0;
|
|
||||||
uint32 flags = ((DMA_MINC_MODE * minc) | DMA_FROM_MEM | DMA_TRNS_CMPLT);
|
|
||||||
uint8 b;
|
|
||||||
dma1_ch3_Active=true;
|
|
||||||
dma_init(_currentSetting->spiDmaDev);
|
|
||||||
// dma_attach_interrupt(DMA1, DMA_CH3, &SPIClass::DMA1_CH3_Event);
|
|
||||||
|
|
||||||
// TX
|
|
||||||
spi_tx_dma_enable(_currentSetting->spi_d);
|
|
||||||
dma_setup_transfer(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, &_currentSetting->spi_d->regs->DR, DMA_SIZE_16BITS,
|
|
||||||
transmitBuf, DMA_SIZE_16BITS, flags);// Transmit buffer DMA
|
|
||||||
dma_set_num_transfers(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, length);
|
|
||||||
dma_enable(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);// enable transmit
|
|
||||||
|
|
||||||
// while (dma1_ch3_Active);
|
|
||||||
while ((dma_get_isr_bits(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel) & 0x2)==0); //Avoid interrupts and just loop waiting for the flag to be set.
|
|
||||||
dma_clear_isr_bits(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);
|
|
||||||
|
|
||||||
while (spi_is_tx_empty(_currentSetting->spi_d) == 0); // "5. Wait until TXE=1 ..."
|
|
||||||
while (spi_is_busy(_currentSetting->spi_d) != 0); // "... and then wait until BSY=0 before disabling the SPI."
|
|
||||||
dma_disable(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);
|
dma_disable(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);
|
||||||
spi_tx_dma_disable(_currentSetting->spi_d);
|
return b;
|
||||||
if (spi_is_rx_nonempty(_currentSetting->spi_d) != 0){; // "4. Wait until RXNE=1 ..."
|
|
||||||
b = spi_rx_reg(_currentSetting->spi_d); // "... and read the last received data."
|
|
||||||
}
|
|
||||||
return b;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SPIClass::attachInterrupt(void) {
|
void SPIClass::attachInterrupt(void) {
|
||||||
// Should be enableInterrupt()
|
// Should be enableInterrupt()
|
||||||
}
|
}
|
||||||
|
@ -536,18 +502,13 @@ uint8 SPIClass::nssPin(void) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
uint8 SPIClass::send(uint8 data) {
|
uint8 SPIClass::send(uint8 data) {
|
||||||
uint8 buf[] = {data};
|
this->write(data);
|
||||||
return this->send(buf, 1);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8 SPIClass::send(uint8 *buf, uint32 len) {
|
uint8 SPIClass::send(uint8 *buf, uint32 len) {
|
||||||
uint32 txed = 0;
|
this->write(buf, len);
|
||||||
uint8 ret = 0;
|
return len;
|
||||||
while (txed < len) {
|
|
||||||
this->write(buf[txed++]);
|
|
||||||
ret = this->read();
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8 SPIClass::recv(void) {
|
uint8 SPIClass::recv(void) {
|
||||||
|
|
|
@ -115,6 +115,13 @@ public:
|
||||||
init_MightInline(clock, bitOrder, dataMode, dataSize);
|
init_MightInline(clock, bitOrder, dataMode, dataSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
SPISettings(uint32_t clock) {
|
||||||
|
if (__builtin_constant_p(clock)) {
|
||||||
|
init_AlwaysInline(clock, MSBFIRST, SPI_MODE0, DATA_SIZE_8BIT);
|
||||||
|
} else {
|
||||||
|
init_MightInline(clock, MSBFIRST, SPI_MODE0, DATA_SIZE_8BIT);
|
||||||
|
}
|
||||||
|
}
|
||||||
SPISettings() { init_AlwaysInline(4000000, MSBFIRST, SPI_MODE0, DATA_SIZE_8BIT); }
|
SPISettings() { init_AlwaysInline(4000000, MSBFIRST, SPI_MODE0, DATA_SIZE_8BIT); }
|
||||||
private:
|
private:
|
||||||
void init_MightInline(uint32_t clock, BitOrder bitOrder, uint8_t dataMode, uint32_t dataSize) {
|
void init_MightInline(uint32_t clock, BitOrder bitOrder, uint8_t dataMode, uint32_t dataSize) {
|
||||||
|
@ -216,40 +223,40 @@ public:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return the next unread byte.
|
* @brief Return the next unread byte/word.
|
||||||
*
|
*
|
||||||
* If there is no unread byte waiting, this function will block
|
* If there is no unread byte/word waiting, this function will block
|
||||||
* until one is received.
|
* until one is received.
|
||||||
*/
|
*/
|
||||||
uint8 read(void);
|
uint16 read(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Read length bytes, storing them into buffer.
|
* @brief Read length bytes, storing them into buffer.
|
||||||
* @param buffer Buffer to store received bytes into.
|
* @param buffer Buffer to store received bytes into.
|
||||||
* @param length Number of bytes to store in buffer. This
|
* @param length Number of bytes to store in buffer. This
|
||||||
* function will block until the desired number of
|
* function will block until the desired number of
|
||||||
* bytes have been read.
|
* bytes have been read.
|
||||||
*/
|
*/
|
||||||
void read(uint8 *buffer, uint32 length);
|
void read(uint8 *buffer, uint32 length);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Transmit a byte.
|
* @brief Transmit one byte/word.
|
||||||
* @param data Byte to transmit.
|
|
||||||
*/
|
|
||||||
// void write(uint8 data);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Transmit a half word.
|
|
||||||
* @param data to transmit.
|
* @param data to transmit.
|
||||||
*/
|
*/
|
||||||
void write(uint16 data);
|
void write(uint16 data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Transmit multiple bytes.
|
* @brief Transmit one byte/word a specified number of times.
|
||||||
* @param buffer Bytes to transmit.
|
* @param data to transmit.
|
||||||
* @param length Number of bytes in buffer to transmit.
|
|
||||||
*/
|
*/
|
||||||
void write(const uint8 *buffer, uint32 length);
|
void write(uint16 data, uint32 n);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Transmit multiple bytes/words.
|
||||||
|
* @param buffer Bytes/words to transmit.
|
||||||
|
* @param length Number of bytes/words in buffer to transmit.
|
||||||
|
*/
|
||||||
|
void write(void * buffer, uint32 length);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Transmit a byte, then return the next unread byte.
|
* @brief Transmit a byte, then return the next unread byte.
|
||||||
|
@ -264,6 +271,7 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sets up a DMA Transfer for "length" bytes.
|
* @brief Sets up a DMA Transfer for "length" bytes.
|
||||||
|
* The transfer mode (8 or 16 bit mode) is evaluated from the SPI peripheral setting.
|
||||||
*
|
*
|
||||||
* This function transmits and receives to buffers.
|
* This function transmits and receives to buffers.
|
||||||
*
|
*
|
||||||
|
@ -271,30 +279,18 @@ public:
|
||||||
* @param receiveBuf buffer Bytes to save received data.
|
* @param receiveBuf buffer Bytes to save received data.
|
||||||
* @param length Number of bytes in buffer to transmit.
|
* @param length Number of bytes in buffer to transmit.
|
||||||
*/
|
*/
|
||||||
uint8 dmaTransfer(uint8 *transmitBuf, uint8 *receiveBuf, uint16 length);
|
uint8 dmaTransfer(void * transmitBuf, void * receiveBuf, uint16 length);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sets up a DMA Transmit for bytes.
|
* @brief Sets up a DMA Transmit for SPI 8 or 16 bit transfer mode.
|
||||||
|
* The transfer mode (8 or 16 bit mode) is evaluated from the SPI peripheral setting.
|
||||||
*
|
*
|
||||||
* This function transmits and does not care about the RX fifo.
|
* This function only transmits and does not care about the RX fifo.
|
||||||
*
|
|
||||||
* @param transmitBuf buffer Bytes to transmit,
|
|
||||||
* @param length Number of bytes in buffer to transmit.
|
|
||||||
* @param minc Set to use Memory Increment mode, clear to use Circular mode.
|
|
||||||
*/
|
|
||||||
uint8 dmaSend(uint8 *transmitBuf, uint16 length, bool minc = 1);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Sets up a DMA Transmit for half words.
|
|
||||||
* SPI PERFIPHERAL MUST BE SET TO 16 BIT MODE BEFORE
|
|
||||||
*
|
|
||||||
* This function transmits and does not care about the RX fifo.
|
|
||||||
*
|
*
|
||||||
* @param data buffer half words to transmit,
|
* @param data buffer half words to transmit,
|
||||||
* @param length Number of bytes in buffer to transmit.
|
* @param length Number of bytes in buffer to transmit.
|
||||||
* @param minc Set to use Memory Increment mode (default if blank), clear to use Circular mode.
|
|
||||||
*/
|
*/
|
||||||
uint8 dmaSend(uint16 *transmitBuf, uint16 length, bool minc = 1);
|
uint8 dmaSend(void * transmitBuf, uint16 length, bool minc = 1);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Pin accessors
|
* Pin accessors
|
||||||
|
|
|
@ -16,13 +16,13 @@ compiler.warning_flags.all=-Wall -Wextra -DDEBUG_LEVEL=DEBUG_ALL
|
||||||
# ----------------------
|
# ----------------------
|
||||||
compiler.path={runtime.tools.arm-none-eabi-gcc.path}/bin/
|
compiler.path={runtime.tools.arm-none-eabi-gcc.path}/bin/
|
||||||
compiler.c.cmd=arm-none-eabi-gcc
|
compiler.c.cmd=arm-none-eabi-gcc
|
||||||
compiler.c.flags=-c -g -Os {compiler.warning_flags} -MMD -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -DBOARD_{build.variant} -D{build.vect} -DERROR_LED_PORT={build.error_led_port} -DERROR_LED_PIN={build.error_led_pin}
|
compiler.c.flags=-c -g -Os {compiler.warning_flags} -std=gnu11 -MMD -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -DBOARD_{build.variant} -D{build.vect} -DERROR_LED_PORT={build.error_led_port} -DERROR_LED_PIN={build.error_led_pin}
|
||||||
compiler.c.elf.cmd=arm-none-eabi-g++
|
compiler.c.elf.cmd=arm-none-eabi-g++
|
||||||
compiler.c.elf.flags=-Os -Wl,--gc-sections
|
compiler.c.elf.flags=-Os -Wl,--gc-sections
|
||||||
compiler.S.cmd=arm-none-eabi-gcc
|
compiler.S.cmd=arm-none-eabi-gcc
|
||||||
compiler.S.flags=-c -g -x assembler-with-cpp -MMD
|
compiler.S.flags=-c -g -x assembler-with-cpp -MMD
|
||||||
compiler.cpp.cmd=arm-none-eabi-g++
|
compiler.cpp.cmd=arm-none-eabi-g++
|
||||||
compiler.cpp.flags=-c -g -Os {compiler.warning_flags} -MMD -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -DBOARD_{build.variant} -D{build.vect} -DERROR_LED_PORT={build.error_led_port} -DERROR_LED_PIN={build.error_led_pin}
|
compiler.cpp.flags=-c -g -Os {compiler.warning_flags} -std=gnu++11 -MMD -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -DBOARD_{build.variant} -D{build.vect} -DERROR_LED_PORT={build.error_led_port} -DERROR_LED_PIN={build.error_led_pin}
|
||||||
compiler.ar.cmd=arm-none-eabi-ar
|
compiler.ar.cmd=arm-none-eabi-ar
|
||||||
compiler.ar.flags=rcs
|
compiler.ar.flags=rcs
|
||||||
compiler.objcopy.cmd=arm-none-eabi-objcopy
|
compiler.objcopy.cmd=arm-none-eabi-objcopy
|
||||||
|
|
|
@ -52,9 +52,9 @@ extern "C"{
|
||||||
* One byte is left free to distinguish empty from full. */
|
* One byte is left free to distinguish empty from full. */
|
||||||
typedef struct ring_buffer {
|
typedef struct ring_buffer {
|
||||||
volatile uint8 *buf; /**< Buffer items are stored into */
|
volatile uint8 *buf; /**< Buffer items are stored into */
|
||||||
uint16 head; /**< Index of the next item to remove */
|
volatile uint16 head; /**< Index of the next item to remove */
|
||||||
uint16 tail; /**< Index where the next item will get inserted */
|
volatile uint16 tail; /**< Index where the next item will get inserted */
|
||||||
uint16 size; /**< Buffer capacity minus one */
|
volatile uint16 size; /**< Buffer capacity minus one */
|
||||||
} ring_buffer;
|
} ring_buffer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -108,6 +108,12 @@ static inline uint32 systick_check_underflow(void) {
|
||||||
return SYSTICK_BASE->CSR & SYSTICK_CSR_COUNTFLAG;
|
return SYSTICK_BASE->CSR & SYSTICK_CSR_COUNTFLAG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief prototype for systick_attach_callback
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
extern void systick_attach_callback(void (*callback)(void));
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -559,7 +559,6 @@ typedef enum dma_mode_flags {
|
||||||
*
|
*
|
||||||
* (It's not possible to fully configure a DMA stream on F2 with just
|
* (It's not possible to fully configure a DMA stream on F2 with just
|
||||||
* this information, so this interface is too tied to the F1.) */
|
* this information, so this interface is too tied to the F1.) */
|
||||||
__deprecated
|
|
||||||
void dma_setup_transfer(dma_dev *dev,
|
void dma_setup_transfer(dma_dev *dev,
|
||||||
dma_channel channel,
|
dma_channel channel,
|
||||||
__io void *peripheral_address,
|
__io void *peripheral_address,
|
||||||
|
|
|
@ -38,7 +38,8 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define CYCLES_PER_MICROSECOND 24
|
//#define CYCLES_PER_MICROSECOND 24
|
||||||
|
#define CYCLES_PER_MICROSECOND (F_CPU / 1000000U)
|
||||||
//#define SYSTICK_RELOAD_VAL (F_CPU/1000) - 1 /* takes a cycle to reload */
|
//#define SYSTICK_RELOAD_VAL (F_CPU/1000) - 1 /* takes a cycle to reload */
|
||||||
#define SYSTICK_RELOAD_VAL 23999 /* takes a cycle to reload */
|
#define SYSTICK_RELOAD_VAL 23999 /* takes a cycle to reload */
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
#ifndef _BOARD_GENERIC_STM32F103C_H_
|
#ifndef _BOARD_GENERIC_STM32F103C_H_
|
||||||
#define _BOARD_GENERIC_STM32F103C_H_
|
#define _BOARD_GENERIC_STM32F103C_H_
|
||||||
|
|
||||||
#define CYCLES_PER_MICROSECOND 72
|
#define CYCLES_PER_MICROSECOND (F_CPU / 1000000U)
|
||||||
#define SYSTICK_RELOAD_VAL (F_CPU/1000) - 1 /* takes a cycle to reload */
|
#define SYSTICK_RELOAD_VAL (F_CPU/1000) - 1 /* takes a cycle to reload */
|
||||||
|
|
||||||
#define BOARD_NR_USARTS 3
|
#define BOARD_NR_USARTS 3
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
#ifndef _BOARD_GENERIC_STM32F103C_H_
|
#ifndef _BOARD_GENERIC_STM32F103C_H_
|
||||||
#define _BOARD_GENERIC_STM32F103C_H_
|
#define _BOARD_GENERIC_STM32F103C_H_
|
||||||
|
|
||||||
#define CYCLES_PER_MICROSECOND 72
|
#define CYCLES_PER_MICROSECOND (F_CPU / 1000000U)
|
||||||
#define SYSTICK_RELOAD_VAL (F_CPU/1000) - 1 /* takes a cycle to reload */
|
#define SYSTICK_RELOAD_VAL (F_CPU/1000) - 1 /* takes a cycle to reload */
|
||||||
|
|
||||||
#define BOARD_NR_USARTS 3
|
#define BOARD_NR_USARTS 3
|
||||||
|
@ -73,6 +73,8 @@
|
||||||
#define BOARD_USB_DISC_DEV GPIOB
|
#define BOARD_USB_DISC_DEV GPIOB
|
||||||
#define BOARD_USB_DISC_BIT 10
|
#define BOARD_USB_DISC_BIT 10
|
||||||
|
|
||||||
|
#define LED_BUILTIN PC13
|
||||||
|
|
||||||
// Note this needs to match with the PIN_MAP array in board.cpp
|
// Note this needs to match with the PIN_MAP array in board.cpp
|
||||||
enum {
|
enum {
|
||||||
PA0, PA1, PA2, PA3, PA4, PA5, PA6, PA7, PA8, PA9, PA10, PA11, PA12, PA13,PA14,PA15,
|
PA0, PA1, PA2, PA3, PA4, PA5, PA6, PA7, PA8, PA9, PA10, PA11, PA12, PA13,PA14,PA15,
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
#ifndef _BOARD_GENERIC_STM32F103R8_H_
|
#ifndef _BOARD_GENERIC_STM32F103R8_H_
|
||||||
#define _BOARD_GENERIC_STM32F103R8_H_
|
#define _BOARD_GENERIC_STM32F103R8_H_
|
||||||
|
|
||||||
#define CYCLES_PER_MICROSECOND 72
|
#define CYCLES_PER_MICROSECOND (F_CPU / 1000000U)
|
||||||
#define SYSTICK_RELOAD_VAL (F_CPU/1000) - 1 /* takes a cycle to reload */
|
#define SYSTICK_RELOAD_VAL (F_CPU/1000) - 1 /* takes a cycle to reload */
|
||||||
|
|
||||||
#define BOARD_NR_USARTS 3
|
#define BOARD_NR_USARTS 3
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
#ifndef _BOARD_GENERIC_STM32F103T_H_
|
#ifndef _BOARD_GENERIC_STM32F103T_H_
|
||||||
#define _BOARD_GENERIC_STM32F103T_H_
|
#define _BOARD_GENERIC_STM32F103T_H_
|
||||||
|
|
||||||
#define CYCLES_PER_MICROSECOND 72
|
#define CYCLES_PER_MICROSECOND (F_CPU / 1000000U)
|
||||||
#define SYSTICK_RELOAD_VAL (F_CPU/1000) - 1 /* takes a cycle to reload */
|
#define SYSTICK_RELOAD_VAL (F_CPU/1000) - 1 /* takes a cycle to reload */
|
||||||
|
|
||||||
#define BOARD_NR_USARTS 2
|
#define BOARD_NR_USARTS 2
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
/* A few of these values will seem strange given that it's a
|
/* A few of these values will seem strange given that it's a
|
||||||
* high-density board. */
|
* high-density board. */
|
||||||
|
|
||||||
#define CYCLES_PER_MICROSECOND 72
|
#define CYCLES_PER_MICROSECOND (F_CPU / 1000000U)
|
||||||
#define SYSTICK_RELOAD_VAL (F_CPU/1000) - 1 /* takes a cycle to reload */
|
#define SYSTICK_RELOAD_VAL (F_CPU/1000) - 1 /* takes a cycle to reload */
|
||||||
|
|
||||||
#define BOARD_BUTTON_PIN PC0
|
#define BOARD_BUTTON_PIN PC0
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
#ifndef _BOARD_GENERIC_STM32F103C_H_
|
#ifndef _BOARD_GENERIC_STM32F103C_H_
|
||||||
#define _BOARD_GENERIC_STM32F103C_H_
|
#define _BOARD_GENERIC_STM32F103C_H_
|
||||||
|
|
||||||
#define CYCLES_PER_MICROSECOND 72
|
#define CYCLES_PER_MICROSECOND (F_CPU / 1000000U)
|
||||||
#define SYSTICK_RELOAD_VAL (F_CPU/1000) - 1 /* takes a cycle to reload */
|
#define SYSTICK_RELOAD_VAL (F_CPU/1000) - 1 /* takes a cycle to reload */
|
||||||
|
|
||||||
#define BOARD_NR_USARTS 2
|
#define BOARD_NR_USARTS 2
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
#define _BOARD_MAPLE_H_
|
#define _BOARD_MAPLE_H_
|
||||||
|
|
||||||
/* 72 MHz -> 72 cycles per microsecond. */
|
/* 72 MHz -> 72 cycles per microsecond. */
|
||||||
#define CYCLES_PER_MICROSECOND 72
|
#define CYCLES_PER_MICROSECOND (F_CPU / 1000000U)
|
||||||
|
|
||||||
/* Roger clark
|
/* Roger clark
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
#ifndef _BOARD_MAPLE_MINI_H_
|
#ifndef _BOARD_MAPLE_MINI_H_
|
||||||
#define _BOARD_MAPLE_MINI_H_
|
#define _BOARD_MAPLE_MINI_H_
|
||||||
|
|
||||||
#define CYCLES_PER_MICROSECOND 72
|
#define CYCLES_PER_MICROSECOND (F_CPU / 1000000U)
|
||||||
#define SYSTICK_RELOAD_VAL (F_CPU/1000) - 1 /* takes a cycle to reload */
|
#define SYSTICK_RELOAD_VAL (F_CPU/1000) - 1 /* takes a cycle to reload */
|
||||||
|
|
||||||
#define BOARD_NR_USARTS 3
|
#define BOARD_NR_USARTS 3
|
||||||
|
@ -71,6 +71,8 @@
|
||||||
#define BOARD_USB_DISC_DEV GPIOB
|
#define BOARD_USB_DISC_DEV GPIOB
|
||||||
#define BOARD_USB_DISC_BIT 9
|
#define BOARD_USB_DISC_BIT 9
|
||||||
|
|
||||||
|
#define LED_BUILTIN PB1
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
PB11, PB10, PB2, PB0, PA7, PA6, PA5, PA4, PA3, PA2, PA1, PA0, PC15, PC14,
|
PB11, PB10, PB2, PB0, PA7, PA6, PA5, PA4, PA3, PA2, PA1, PA0, PC15, PC14,
|
||||||
PC13, PB7, PB6, PB5, PB4, PB3, PA15, PA14, PA13, PA12, PA11, PA10, PA9,
|
PC13, PB7, PB6, PB5, PB4, PB3, PA15, PA14, PA13, PA12, PA11, PA10, PA9,
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
#ifndef _BOARD_MICRODUINO_STM32_H_
|
#ifndef _BOARD_MICRODUINO_STM32_H_
|
||||||
#define _BOARD_MICRODUINO_STM32_H_
|
#define _BOARD_MICRODUINO_STM32_H_
|
||||||
|
|
||||||
#define CYCLES_PER_MICROSECOND 72
|
#define CYCLES_PER_MICROSECOND (F_CPU / 1000000U)
|
||||||
#define SYSTICK_RELOAD_VAL (F_CPU/1000) - 1 /* takes a cycle to reload */
|
#define SYSTICK_RELOAD_VAL (F_CPU/1000) - 1 /* takes a cycle to reload */
|
||||||
|
|
||||||
/* Roger Clark.
|
/* Roger Clark.
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
#ifndef _BOARD_MAPLE_H_
|
#ifndef _BOARD_MAPLE_H_
|
||||||
#define _BOARD_MAPLE_H_
|
#define _BOARD_MAPLE_H_
|
||||||
#define _BOARD_NUCLEOF103RB_ 1 // hack for HardwareSerial.cpp for a new order of serials
|
#define _BOARD_NUCLEOF103RB_ 1 // hack for HardwareSerial.cpp for a new order of serials
|
||||||
#define CYCLES_PER_MICROSECOND 72
|
#define CYCLES_PER_MICROSECOND (F_CPU / 1000000U)
|
||||||
#define SYSTICK_RELOAD_VAL (F_CPU/1000) - 1 /* takes a cycle to reload */
|
#define SYSTICK_RELOAD_VAL (F_CPU/1000) - 1 /* takes a cycle to reload */
|
||||||
|
|
||||||
/* Roger clark. Removed defines for LED pin and Button pin as they are not Arduino API defines */
|
/* Roger clark. Removed defines for LED pin and Button pin as they are not Arduino API defines */
|
||||||
|
|
|
@ -38,8 +38,8 @@
|
||||||
|
|
||||||
#include <libmaple/stm32.h>
|
#include <libmaple/stm32.h>
|
||||||
|
|
||||||
#define CYCLES_PER_MICROSECOND 72
|
#define CYCLES_PER_MICROSECOND (F_CPU / 1000000U)
|
||||||
#define SYSTICK_RELOAD_VAL 71999 /* takes a cycle to reload */
|
#define SYSTICK_RELOAD_VAL (F_CPU/1000) - 1 /* takes a cycle to reload */
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
PC13, PC14, PC15,
|
PC13, PC14, PC15,
|
||||||
|
|
|
@ -120,8 +120,12 @@ extern char* ltoa( long value, char *string, int radix )
|
||||||
|
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
#if __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ > 9 || \
|
||||||
|
(__GNUC_MINOR__ == 9 && __GNUC_PATCHLEVEL__ > 2)))
|
||||||
|
extern char* utoa( unsigned value, char *string, int radix )
|
||||||
|
#else
|
||||||
extern char* utoa( unsigned long value, char *string, int radix )
|
extern char* utoa( unsigned long value, char *string, int radix )
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
return ultoa( value, string, radix ) ;
|
return ultoa( value, string, radix ) ;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,12 @@ extern void itoa( int n, char s[] ) ;
|
||||||
|
|
||||||
extern char* itoa( int value, char *string, int radix ) ;
|
extern char* itoa( int value, char *string, int radix ) ;
|
||||||
extern char* ltoa( long value, char *string, int radix ) ;
|
extern char* ltoa( long value, char *string, int radix ) ;
|
||||||
|
#if __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ > 9 || \
|
||||||
|
(__GNUC_MINOR__ == 9 && __GNUC_PATCHLEVEL__ > 2)))
|
||||||
|
extern char* utoa( unsigned value, char *string, int radix ) ;
|
||||||
|
#else
|
||||||
extern char* utoa( unsigned long value, char *string, int radix ) ;
|
extern char* utoa( unsigned long value, char *string, int radix ) ;
|
||||||
|
#endif
|
||||||
extern char* ultoa( unsigned long value, char *string, int radix ) ;
|
extern char* ultoa( unsigned long value, char *string, int radix ) ;
|
||||||
#endif /* 0 */
|
#endif /* 0 */
|
||||||
|
|
||||||
|
|
|
@ -166,7 +166,7 @@ extern const adc_dev *ADC3;
|
||||||
#define ADC_CR2_ALIGN_BIT 11
|
#define ADC_CR2_ALIGN_BIT 11
|
||||||
#define ADC_CR2_JEXTTRIG_BIT 15
|
#define ADC_CR2_JEXTTRIG_BIT 15
|
||||||
#define ADC_CR2_EXTTRIG_BIT 20
|
#define ADC_CR2_EXTTRIG_BIT 20
|
||||||
#define ADC_CR2_TSEREFE_BIT 23
|
#define ADC_CR2_TSVREFE_BIT 23
|
||||||
#ifdef STM32F2
|
#ifdef STM32F2
|
||||||
#define ADC_CR2_JSWSTART_BIT 22
|
#define ADC_CR2_JSWSTART_BIT 22
|
||||||
#define ADC_CR2_SWSTART_BIT 30
|
#define ADC_CR2_SWSTART_BIT 30
|
||||||
|
@ -191,7 +191,7 @@ extern const adc_dev *ADC3;
|
||||||
#define ADC_CR2_EXTTRIG BIT(ADC_CR2_EXTTRIG_BIT)
|
#define ADC_CR2_EXTTRIG BIT(ADC_CR2_EXTTRIG_BIT)
|
||||||
#define ADC_CR2_JSWSTART BIT(ADC_CR2_JSWSTART_BIT)
|
#define ADC_CR2_JSWSTART BIT(ADC_CR2_JSWSTART_BIT)
|
||||||
#define ADC_CR2_SWSTART BIT(ADC_CR2_SWSTART_BIT)
|
#define ADC_CR2_SWSTART BIT(ADC_CR2_SWSTART_BIT)
|
||||||
#define ADC_CR2_TSEREFE BIT(ADC_CR2_TSEREFE_BIT)
|
#define ADC_CR2_TSVREFE BIT(ADC_CR2_TSVREFE_BIT)
|
||||||
|
|
||||||
/* Sample time register 1 */
|
/* Sample time register 1 */
|
||||||
|
|
||||||
|
|
|
@ -12,13 +12,13 @@ version=0.1.0
|
||||||
|
|
||||||
compiler.path={runtime.tools.arm-none-eabi-gcc.path}/bin/
|
compiler.path={runtime.tools.arm-none-eabi-gcc.path}/bin/
|
||||||
compiler.c.cmd=arm-none-eabi-gcc
|
compiler.c.cmd=arm-none-eabi-gcc
|
||||||
compiler.c.flags=-c -g -Os -w -MMD -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -DBOARD_{build.variant} -D{build.vect} -DERROR_LED_PORT={build.error_led_port} -DERROR_LED_PIN={build.error_led_pin}
|
compiler.c.flags=-c -g -Os -w -MMD -std=gnu11 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -DBOARD_{build.variant} -D{build.vect} -DERROR_LED_PORT={build.error_led_port} -DERROR_LED_PIN={build.error_led_pin}
|
||||||
compiler.c.elf.cmd=arm-none-eabi-g++
|
compiler.c.elf.cmd=arm-none-eabi-g++
|
||||||
compiler.c.elf.flags=-Os -Wl,--gc-sections
|
compiler.c.elf.flags=-Os -Wl,--gc-sections
|
||||||
compiler.S.cmd=arm-none-eabi-gcc
|
compiler.S.cmd=arm-none-eabi-gcc
|
||||||
compiler.S.flags=-c -g -x assembler-with-cpp -MMD
|
compiler.S.flags=-c -g -x assembler-with-cpp -MMD
|
||||||
compiler.cpp.cmd=arm-none-eabi-g++
|
compiler.cpp.cmd=arm-none-eabi-g++
|
||||||
compiler.cpp.flags=-c -g -Os -w -MMD -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -DBOARD_{build.variant} -D{build.vect} -DERROR_LED_PORT={build.error_led_port} -DERROR_LED_PIN={build.error_led_pin}
|
compiler.cpp.flags=-c -g -Os -w -MMD -std=gnu++11 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -DBOARD_{build.variant} -D{build.vect} -DERROR_LED_PORT={build.error_led_port} -DERROR_LED_PIN={build.error_led_pin}
|
||||||
compiler.ar.cmd=arm-none-eabi-ar
|
compiler.ar.cmd=arm-none-eabi-ar
|
||||||
compiler.ar.flags=rcs
|
compiler.ar.flags=rcs
|
||||||
compiler.objcopy.cmd=arm-none-eabi-objcopy
|
compiler.objcopy.cmd=arm-none-eabi-objcopy
|
||||||
|
|
|
@ -38,3 +38,12 @@ if [ ! -x "${DFU_UTIL}" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
"${DFU_UTIL}" -d ${usbID} -a ${altID} -D ${binfile} ${dfuse_addr} -R
|
"${DFU_UTIL}" -d ${usbID} -a ${altID} -D ${binfile} ${dfuse_addr} -R
|
||||||
|
|
||||||
|
echo -n Waiting for ${dummy_port_fullpath} serial...
|
||||||
|
|
||||||
|
COUNTER=0
|
||||||
|
while [ ! -c ${dummy_port_fullpath} ] && ((COUNTER++ < 40)); do
|
||||||
|
sleep 0.1
|
||||||
|
done
|
||||||
|
|
||||||
|
echo Done
|
||||||
|
|
|
@ -38,3 +38,12 @@ if [ ! -x "${DFU_UTIL}" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
"${DFU_UTIL}" -d ${usbID} -a ${altID} -D ${binfile} ${dfuse_addr} -R
|
"${DFU_UTIL}" -d ${usbID} -a ${altID} -D ${binfile} ${dfuse_addr} -R
|
||||||
|
|
||||||
|
echo -n Waiting for ${dummy_port_fullpath} serial...
|
||||||
|
|
||||||
|
COUNTER=0
|
||||||
|
while [ ! -c ${dummy_port_fullpath} ] && ((COUNTER++ < 40)); do
|
||||||
|
sleep 0.1
|
||||||
|
done
|
||||||
|
|
||||||
|
echo Done
|
|
@ -51,3 +51,12 @@ if [ ! -x ${DFU_UTIL} ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
${DFU_UTIL} -d ${usbID} -a ${altID} -D ${binfile} -R ${dfuse_addr} -R
|
${DFU_UTIL} -d ${usbID} -a ${altID} -D ${binfile} -R ${dfuse_addr} -R
|
||||||
|
|
||||||
|
echo -n Waiting for ${dummy_port_fullpath} serial...
|
||||||
|
|
||||||
|
COUNTER=0
|
||||||
|
while [ ! -c ${dummy_port_fullpath} ] && ((COUNTER++ < 40)); do
|
||||||
|
sleep 0.1
|
||||||
|
done
|
||||||
|
|
||||||
|
echo Done
|
||||||
|
|
|
@ -6,3 +6,13 @@ set driverLetter=%driverLetter:~0,2%
|
||||||
%driverLetter%
|
%driverLetter%
|
||||||
cd %~dp0
|
cd %~dp0
|
||||||
java -jar maple_loader.jar %1 %2 %3 %4 %5 %6 %7 %8 %9
|
java -jar maple_loader.jar %1 %2 %3 %4 %5 %6 %7 %8 %9
|
||||||
|
|
||||||
|
for /l %%x in (1, 1, 40) do (
|
||||||
|
ping -w 50 -n 1 192.0.2.1 > nul
|
||||||
|
mode %1 > nul
|
||||||
|
if ERRORLEVEL 0 goto comPortFound
|
||||||
|
)
|
||||||
|
|
||||||
|
echo timeout waiting for %1 serial
|
||||||
|
|
||||||
|
:comPortFound
|
||||||
|
|
Loading…
Reference in New Issue