Skip to content

Commit 4aa7306

Browse files
authored
Merge pull request #2 from stm32duino/master
Update of master
2 parents 5604b1f + 2280453 commit 4aa7306

File tree

13 files changed

+797
-9
lines changed

13 files changed

+797
-9
lines changed

CI/astyle/.astyleignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
.git
22
BUILD
33
CI
4-
system/Drivers
5-
system/STM32*
4+
system

CI/astyle/astyle.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ def checkAstyle():
7272
sys.exit(1)
7373
else:
7474
raise subprocess.CalledProcessError(1, "No version found")
75+
except FileNotFoundError:
76+
print("Astyle binary not found.")
77+
print("Check if it is in the PATH environment or use '-p <path>'.")
78+
sys.exit(1)
7579
except subprocess.CalledProcessError as e:
7680
print(e.output)
7781
sys.exit(1)
@@ -128,7 +132,11 @@ def manage_exclude_list():
128132
exclude_list.append(line.rstrip())
129133
if exclude_list:
130134
for pattern in exclude_list:
131-
exclude_pattern = re.compile(os.path.join(src_path, pattern) + ".*")
135+
if sys.platform.startswith("win32"):
136+
winpattern = os.path.join(src_path, pattern.replace("/","\\")) .replace("\\","\\\\")
137+
exclude_pattern = re.compile(winpattern + ".*")
138+
else:
139+
exclude_pattern = re.compile(os.path.join(src_path, pattern) + ".*")
132140
for s in reversed(source_list):
133141
if exclude_pattern.search(s):
134142
source_list.remove(s)

cores/arduino/pins_arduino.h

+11
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ enum {
5151
};
5252

5353
// Arduino analog pins
54+
#ifndef NUM_ANALOG_INPUTS
55+
#define NUM_ANALOG_INPUTS 0
56+
#endif
57+
#ifndef NUM_ANALOG_FIRST
58+
#define NUM_ANALOG_FIRST NUM_DIGITAL_PINS
59+
#endif
60+
5461
// Analog pins must be contiguous to be able to loop on each value
5562
#define MAX_ANALOG_INPUTS 24
5663
_Static_assert(NUM_ANALOG_INPUTS <= MAX_ANALOG_INPUTS,
@@ -230,8 +237,12 @@ extern const PinName digitalPin[];
230237
uint32_t pinNametoDigitalPin(PinName p);
231238

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

cores/arduino/stm32/analog.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ extern "C" {
4747

4848

4949
/* Private_Variables */
50-
#if defined(HAL_ADC_MODULE_ENABLED) || defined(HAL_DAC_MODULE_ENABLED) ||\
51-
defined(HAL_TIM_MODULE_ENABLED)
50+
#if defined(HAL_ADC_MODULE_ENABLED) || defined(HAL_DAC_MODULE_ENABLED)
5251
static PinName g_current_pin = NC;
5352
#endif
5453

cores/arduino/stm32/twi.c

+43-4
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ extern "C" {
6262
#ifndef I2C_VALID_TIMING_NBR
6363
#define I2C_VALID_TIMING_NBR 8U
6464
#endif
65-
#define I2C_SPEED_FREQ_STANDARD 0U /* 100 kHz */
66-
#define I2C_SPEED_FREQ_FAST 1U /* 400 kHz */
67-
#define I2C_SPEED_FREQ_FAST_PLUS 2U /* 1 MHz */
6865
#define I2C_ANALOG_FILTER_DELAY_MIN 50U /* ns */
6966
#ifndef I2C_ANALOG_FILTER_DELAY_MAX
7067
#define I2C_ANALOG_FILTER_DELAY_MAX 260U /* ns */
@@ -82,6 +79,20 @@ extern "C" {
8279
#define I2C_SCLL_MAX 256U
8380
#define SEC2NSEC 1000000000UL
8481

82+
typedef enum {
83+
I2C_SPEED_FREQ_STANDARD, /* 100 kHz */
84+
I2C_SPEED_FREQ_FAST, /* 400 kHz */
85+
I2C_SPEED_FREQ_FAST_PLUS, /* 1 MHz */
86+
I2C_SPEED_FREQ_NUMBER /* Must be the last entry */
87+
} I2C_speed_freq_t;
88+
89+
typedef struct {
90+
uint32_t input_clock; /* I2C Input clock */
91+
uint32_t timing; /* I2C timing corresponding to Input clock */
92+
} I2C_timing_t;
93+
94+
static I2C_timing_t I2C_ClockTiming[I2C_SPEED_FREQ_NUMBER] = {0};
95+
8596
typedef struct {
8697
uint32_t freq; /* Frequency in Hz */
8798
uint32_t freq_min; /* Minimum frequency in Hz */
@@ -354,6 +365,17 @@ static uint32_t i2c_computeTiming(uint32_t clkSrcFreq, uint32_t i2c_speed)
354365
uint8_t presc, scldel, sdadel;
355366
uint32_t tafdel_min, tafdel_max;
356367

368+
if (i2c_speed > I2C_SPEED_FREQ_NUMBER) {
369+
return ret;
370+
}
371+
/* Don't compute timing if already available value for the requested speed with the same I2C input frequency */
372+
if ((I2C_ClockTiming[i2c_speed].input_clock == clkSrcFreq) && (I2C_ClockTiming[i2c_speed].timing != 0U)) {
373+
return I2C_ClockTiming[i2c_speed].timing;
374+
}
375+
376+
/* Save the I2C input clock for which the timing will be saved */
377+
I2C_ClockTiming[i2c_speed].input_clock = clkSrcFreq;
378+
357379
ti2cclk = (SEC2NSEC + (clkSrcFreq / 2U)) / clkSrcFreq;
358380
ti2cspeed = (SEC2NSEC + (I2C_Charac[i2c_speed].freq / 2U)) / I2C_Charac[i2c_speed].freq;
359381

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

743+
#if defined(I2C_OTHER_FRAME)
744+
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
745+
#endif
746+
719747
do {
748+
#if defined(I2C_OTHER_FRAME)
749+
if (HAL_I2C_Master_Seq_Transmit_IT(&(obj->handle), dev_address, data, size, XferOptions) == HAL_OK) {
750+
#else
720751
if (HAL_I2C_Master_Transmit_IT(&(obj->handle), dev_address, data, size) == HAL_OK) {
752+
#endif
721753
ret = I2C_OK;
722754
// wait for transfer completion
723755
while ((HAL_I2C_GetState(&(obj->handle)) != HAL_I2C_STATE_READY)
@@ -736,7 +768,6 @@ i2c_status_e i2c_master_write(i2c_t *obj, uint8_t dev_address,
736768
Master restarts communication */
737769
} while (((HAL_I2C_GetError(&(obj->handle)) & HAL_I2C_ERROR_AF) == HAL_I2C_ERROR_AF)
738770
&& (delta < I2C_TIMEOUT_TICK));
739-
740771
return ret;
741772
}
742773

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

814+
#if defined(I2C_OTHER_FRAME)
815+
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
816+
#endif
817+
783818
do {
819+
#if defined(I2C_OTHER_FRAME)
820+
if (HAL_I2C_Master_Seq_Receive_IT(&(obj->handle), dev_address, data, size, XferOptions) == HAL_OK) {
821+
#else
784822
if (HAL_I2C_Master_Receive_IT(&(obj->handle), dev_address, data, size) == HAL_OK) {
823+
#endif
785824
ret = I2C_OK;
786825
// wait for transfer completion
787826
while ((HAL_I2C_GetState(&(obj->handle)) != HAL_I2C_STATE_READY)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
Software serial multple serial test
3+
4+
Receives from the hardware serial, sends to software serial.
5+
Receives from software serial, sends to hardware serial.
6+
7+
The circuit:
8+
* RX is digital pin 10 (connect to TX of other device)
9+
* TX is digital pin 11 (connect to RX of other device)
10+
11+
created back in the mists of time
12+
modified 25 May 2012
13+
by Tom Igoe
14+
based on Mikal Hart's example
15+
16+
This example code is in the public domain.
17+
18+
*/
19+
#include <SoftwareSerial.h>
20+
21+
SoftwareSerial mySerial(10, 11); // RX, TX
22+
23+
void setup() {
24+
// Open serial communications and wait for port to open:
25+
Serial.begin(57600);
26+
while (!Serial) {
27+
; // wait for serial port to connect. Needed for native USB port only
28+
}
29+
30+
31+
Serial.println("Goodnight moon!");
32+
33+
// set the data rate for the SoftwareSerial port
34+
mySerial.begin(4800);
35+
mySerial.println("Hello, world?");
36+
}
37+
38+
void loop() { // run over and over
39+
if (mySerial.available()) {
40+
Serial.write(mySerial.read());
41+
}
42+
if (Serial.available()) {
43+
mySerial.write(Serial.read());
44+
}
45+
}
46+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
Software serial multple serial test
3+
4+
Receives from the two software serial ports,
5+
sends to the hardware serial port.
6+
7+
In order to listen on a software port, you call port.listen().
8+
When using two software serial ports, you have to switch ports
9+
by listen()ing on each one in turn. Pick a logical time to switch
10+
ports, like the end of an expected transmission, or when the
11+
buffer is empty. This example switches ports when there is nothing
12+
more to read from a port
13+
14+
The circuit:
15+
Two devices which communicate serially are needed.
16+
* First serial device's TX attached to digital pin 10(RX), RX to pin 11(TX)
17+
* Second serial device's TX attached to digital pin 8(RX), RX to pin 9(TX)
18+
19+
20+
created 18 Apr. 2011
21+
modified 19 March 2016
22+
by Tom Igoe
23+
based on Mikal Hart's twoPortRXExample
24+
25+
This example code is in the public domain.
26+
27+
*/
28+
29+
#include <SoftwareSerial.h>
30+
// software serial #1: RX = digital pin 10, TX = digital pin 11
31+
SoftwareSerial portOne(10, 11);
32+
33+
// software serial #2: RX = digital pin 8, TX = digital pin 9
34+
// on the Mega, use other pins instead, since 8 and 9 don't work on the Mega
35+
SoftwareSerial portTwo(8, 9);
36+
37+
void setup() {
38+
// Open serial communications and wait for port to open:
39+
Serial.begin(9600);
40+
while (!Serial) {
41+
; // wait for serial port to connect. Needed for native USB port only
42+
}
43+
44+
45+
// Start each software serial port
46+
portOne.begin(9600);
47+
portTwo.begin(9600);
48+
}
49+
50+
void loop() {
51+
// By default, the last intialized port is listening.
52+
// when you want to listen on a port, explicitly select it:
53+
portOne.listen();
54+
Serial.println("Data from port one:");
55+
// while there is data coming in, read it
56+
// and send to the hardware serial port:
57+
while (portOne.available() > 0) {
58+
char inByte = portOne.read();
59+
Serial.write(inByte);
60+
}
61+
62+
// blank line to separate data from the two ports:
63+
Serial.println();
64+
65+
// Now listen on the second port
66+
portTwo.listen();
67+
// while there is data coming in, read it
68+
// and send to the hardware serial port:
69+
Serial.println("Data from port two:");
70+
while (portTwo.available() > 0) {
71+
char inByte = portTwo.read();
72+
Serial.write(inByte);
73+
}
74+
75+
// blank line to separate data from the two ports:
76+
Serial.println();
77+
}

libraries/SoftwareSerial/keywords.txt

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#######################################
2+
# Syntax Coloring Map for SoftwareSerial
3+
# (formerly NewSoftSerial)
4+
#######################################
5+
6+
#######################################
7+
# Datatypes (KEYWORD1)
8+
#######################################
9+
10+
SoftwareSerial KEYWORD1
11+
12+
#######################################
13+
# Methods and Functions (KEYWORD2)
14+
#######################################
15+
16+
begin KEYWORD2
17+
end KEYWORD2
18+
read KEYWORD2
19+
write KEYWORD2
20+
available KEYWORD2
21+
isListening KEYWORD2
22+
overflow KEYWORD2
23+
flush KEYWORD2
24+
listen KEYWORD2
25+
peek KEYWORD2
26+
27+
#######################################
28+
# Constants (LITERAL1)
29+
#######################################
30+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name=SoftwareSerial
2+
version=1.0
3+
author=Arduino, Armin van der Togt
4+
maintainer=stm32duino
5+
sentence=Enables serial communication on any digital pin.
6+
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.
7+
category=Communication
8+
url=http://www.arduino.cc/en/Reference/SoftwareSerial
9+
architectures=stm32
10+

0 commit comments

Comments
 (0)