Skip to content

Update of master #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions CI/astyle/.astyleignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.git
BUILD
CI
system/Drivers
system/STM32*
system
10 changes: 9 additions & 1 deletion CI/astyle/astyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ def checkAstyle():
sys.exit(1)
else:
raise subprocess.CalledProcessError(1, "No version found")
except FileNotFoundError:
print("Astyle binary not found.")
print("Check if it is in the PATH environment or use '-p <path>'.")
sys.exit(1)
except subprocess.CalledProcessError as e:
print(e.output)
sys.exit(1)
Expand Down Expand Up @@ -128,7 +132,11 @@ def manage_exclude_list():
exclude_list.append(line.rstrip())
if exclude_list:
for pattern in exclude_list:
exclude_pattern = re.compile(os.path.join(src_path, pattern) + ".*")
if sys.platform.startswith("win32"):
winpattern = os.path.join(src_path, pattern.replace("/","\\")) .replace("\\","\\\\")
exclude_pattern = re.compile(winpattern + ".*")
else:
exclude_pattern = re.compile(os.path.join(src_path, pattern) + ".*")
for s in reversed(source_list):
if exclude_pattern.search(s):
source_list.remove(s)
Expand Down
11 changes: 11 additions & 0 deletions cores/arduino/pins_arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ enum {
};

// Arduino analog pins
#ifndef NUM_ANALOG_INPUTS
#define NUM_ANALOG_INPUTS 0
#endif
#ifndef NUM_ANALOG_FIRST
#define NUM_ANALOG_FIRST NUM_DIGITAL_PINS
#endif

// Analog pins must be contiguous to be able to loop on each value
#define MAX_ANALOG_INPUTS 24
_Static_assert(NUM_ANALOG_INPUTS <= MAX_ANALOG_INPUTS,
Expand Down Expand Up @@ -230,8 +237,12 @@ extern const PinName digitalPin[];
uint32_t pinNametoDigitalPin(PinName p);

// Convert an analog pin number to a digital pin number
#if defined(NUM_ANALOG_INPUTS) && (NUM_ANALOG_INPUTS>0)
// Used by analogRead api to have A0 == 0
#define analogInputToDigitalPin(p) (((uint32_t)p < NUM_ANALOG_INPUTS) ? (p+A0) : p)
#else
#define analogInputToDigitalPin(p) (NUM_DIGITAL_PINS)
#endif
// Convert an analog pin number Axx to a PinName PX_n
PinName analogInputToPinName(uint32_t pin);

Expand Down
3 changes: 1 addition & 2 deletions cores/arduino/stm32/analog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ extern "C" {


/* Private_Variables */
#if defined(HAL_ADC_MODULE_ENABLED) || defined(HAL_DAC_MODULE_ENABLED) ||\
defined(HAL_TIM_MODULE_ENABLED)
#if defined(HAL_ADC_MODULE_ENABLED) || defined(HAL_DAC_MODULE_ENABLED)
static PinName g_current_pin = NC;
#endif

Expand Down
47 changes: 43 additions & 4 deletions cores/arduino/stm32/twi.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ extern "C" {
#ifndef I2C_VALID_TIMING_NBR
#define I2C_VALID_TIMING_NBR 8U
#endif
#define I2C_SPEED_FREQ_STANDARD 0U /* 100 kHz */
#define I2C_SPEED_FREQ_FAST 1U /* 400 kHz */
#define I2C_SPEED_FREQ_FAST_PLUS 2U /* 1 MHz */
#define I2C_ANALOG_FILTER_DELAY_MIN 50U /* ns */
#ifndef I2C_ANALOG_FILTER_DELAY_MAX
#define I2C_ANALOG_FILTER_DELAY_MAX 260U /* ns */
Expand All @@ -82,6 +79,20 @@ extern "C" {
#define I2C_SCLL_MAX 256U
#define SEC2NSEC 1000000000UL

typedef enum {
I2C_SPEED_FREQ_STANDARD, /* 100 kHz */
I2C_SPEED_FREQ_FAST, /* 400 kHz */
I2C_SPEED_FREQ_FAST_PLUS, /* 1 MHz */
I2C_SPEED_FREQ_NUMBER /* Must be the last entry */
} I2C_speed_freq_t;

typedef struct {
uint32_t input_clock; /* I2C Input clock */
uint32_t timing; /* I2C timing corresponding to Input clock */
} I2C_timing_t;

static I2C_timing_t I2C_ClockTiming[I2C_SPEED_FREQ_NUMBER] = {0};

typedef struct {
uint32_t freq; /* Frequency in Hz */
uint32_t freq_min; /* Minimum frequency in Hz */
Expand Down Expand Up @@ -354,6 +365,17 @@ static uint32_t i2c_computeTiming(uint32_t clkSrcFreq, uint32_t i2c_speed)
uint8_t presc, scldel, sdadel;
uint32_t tafdel_min, tafdel_max;

if (i2c_speed > I2C_SPEED_FREQ_NUMBER) {
return ret;
}
/* Don't compute timing if already available value for the requested speed with the same I2C input frequency */
if ((I2C_ClockTiming[i2c_speed].input_clock == clkSrcFreq) && (I2C_ClockTiming[i2c_speed].timing != 0U)) {
return I2C_ClockTiming[i2c_speed].timing;
}

/* Save the I2C input clock for which the timing will be saved */
I2C_ClockTiming[i2c_speed].input_clock = clkSrcFreq;

ti2cclk = (SEC2NSEC + (clkSrcFreq / 2U)) / clkSrcFreq;
ti2cspeed = (SEC2NSEC + (I2C_Charac[i2c_speed].freq / 2U)) / I2C_Charac[i2c_speed].freq;

Expand Down Expand Up @@ -437,6 +459,8 @@ static uint32_t i2c_computeTiming(uint32_t clkSrcFreq, uint32_t i2c_speed)
((sclh & 0xFFU) << 8) | \
((scll & 0xFFU) << 0);
prev_presc = presc;
/* Save I2C Timing found for further reuse (and avoid to compute again) */
I2C_ClockTiming[i2c_speed].timing = ret;
}
}
}
Expand Down Expand Up @@ -716,8 +740,16 @@ i2c_status_e i2c_master_write(i2c_t *obj, uint8_t dev_address,
return i2c_IsDeviceReady(obj, dev_address, 1);
}

#if defined(I2C_OTHER_FRAME)
uint32_t XferOptions = obj->handle.XferOptions; // save XferOptions value, because handle can be modified by HAL, which cause issue in case of NACK from slave
#endif

do {
#if defined(I2C_OTHER_FRAME)
if (HAL_I2C_Master_Seq_Transmit_IT(&(obj->handle), dev_address, data, size, XferOptions) == HAL_OK) {
#else
if (HAL_I2C_Master_Transmit_IT(&(obj->handle), dev_address, data, size) == HAL_OK) {
#endif
ret = I2C_OK;
// wait for transfer completion
while ((HAL_I2C_GetState(&(obj->handle)) != HAL_I2C_STATE_READY)
Expand All @@ -736,7 +768,6 @@ i2c_status_e i2c_master_write(i2c_t *obj, uint8_t dev_address,
Master restarts communication */
} while (((HAL_I2C_GetError(&(obj->handle)) & HAL_I2C_ERROR_AF) == HAL_I2C_ERROR_AF)
&& (delta < I2C_TIMEOUT_TICK));

return ret;
}

Expand Down Expand Up @@ -780,8 +811,16 @@ i2c_status_e i2c_master_read(i2c_t *obj, uint8_t dev_address, uint8_t *data, uin
uint32_t tickstart = HAL_GetTick();
uint32_t delta = 0;

#if defined(I2C_OTHER_FRAME)
uint32_t XferOptions = obj->handle.XferOptions; // save XferOptions value, because handle can be modified by HAL, which cause issue in case of NACK from slave
#endif

do {
#if defined(I2C_OTHER_FRAME)
if (HAL_I2C_Master_Seq_Receive_IT(&(obj->handle), dev_address, data, size, XferOptions) == HAL_OK) {
#else
if (HAL_I2C_Master_Receive_IT(&(obj->handle), dev_address, data, size) == HAL_OK) {
#endif
ret = I2C_OK;
// wait for transfer completion
while ((HAL_I2C_GetState(&(obj->handle)) != HAL_I2C_STATE_READY)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
Software serial multple serial test

Receives from the hardware serial, sends to software serial.
Receives from software serial, sends to hardware serial.

The circuit:
* RX is digital pin 10 (connect to TX of other device)
* TX is digital pin 11 (connect to RX of other device)

created back in the mists of time
modified 25 May 2012
by Tom Igoe
based on Mikal Hart's example

This example code is in the public domain.

*/
#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(57600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}


Serial.println("Goodnight moon!");

// set the data rate for the SoftwareSerial port
mySerial.begin(4800);
mySerial.println("Hello, world?");
}

void loop() { // run over and over
if (mySerial.available()) {
Serial.write(mySerial.read());
}
if (Serial.available()) {
mySerial.write(Serial.read());
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
Software serial multple serial test

Receives from the two software serial ports,
sends to the hardware serial port.

In order to listen on a software port, you call port.listen().
When using two software serial ports, you have to switch ports
by listen()ing on each one in turn. Pick a logical time to switch
ports, like the end of an expected transmission, or when the
buffer is empty. This example switches ports when there is nothing
more to read from a port

The circuit:
Two devices which communicate serially are needed.
* First serial device's TX attached to digital pin 10(RX), RX to pin 11(TX)
* Second serial device's TX attached to digital pin 8(RX), RX to pin 9(TX)


created 18 Apr. 2011
modified 19 March 2016
by Tom Igoe
based on Mikal Hart's twoPortRXExample

This example code is in the public domain.

*/

#include <SoftwareSerial.h>
// software serial #1: RX = digital pin 10, TX = digital pin 11
SoftwareSerial portOne(10, 11);

// software serial #2: RX = digital pin 8, TX = digital pin 9
// on the Mega, use other pins instead, since 8 and 9 don't work on the Mega
SoftwareSerial portTwo(8, 9);

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}


// Start each software serial port
portOne.begin(9600);
portTwo.begin(9600);
}

void loop() {
// By default, the last intialized port is listening.
// when you want to listen on a port, explicitly select it:
portOne.listen();
Serial.println("Data from port one:");
// while there is data coming in, read it
// and send to the hardware serial port:
while (portOne.available() > 0) {
char inByte = portOne.read();
Serial.write(inByte);
}

// blank line to separate data from the two ports:
Serial.println();

// Now listen on the second port
portTwo.listen();
// while there is data coming in, read it
// and send to the hardware serial port:
Serial.println("Data from port two:");
while (portTwo.available() > 0) {
char inByte = portTwo.read();
Serial.write(inByte);
}

// blank line to separate data from the two ports:
Serial.println();
}
30 changes: 30 additions & 0 deletions libraries/SoftwareSerial/keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#######################################
# Syntax Coloring Map for SoftwareSerial
# (formerly NewSoftSerial)
#######################################

#######################################
# Datatypes (KEYWORD1)
#######################################

SoftwareSerial KEYWORD1

#######################################
# Methods and Functions (KEYWORD2)
#######################################

begin KEYWORD2
end KEYWORD2
read KEYWORD2
write KEYWORD2
available KEYWORD2
isListening KEYWORD2
overflow KEYWORD2
flush KEYWORD2
listen KEYWORD2
peek KEYWORD2

#######################################
# Constants (LITERAL1)
#######################################

10 changes: 10 additions & 0 deletions libraries/SoftwareSerial/library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name=SoftwareSerial
version=1.0
author=Arduino, Armin van der Togt
maintainer=stm32duino
sentence=Enables serial communication on any digital pin.
paragraph=The SoftwareSerial library has been developed to allow serial communication on any digital pin of the board, using software to replicate the functionality of the hardware UART. It is possible to have multiple software serial ports.
category=Communication
url=http://www.arduino.cc/en/Reference/SoftwareSerial
architectures=stm32

Loading