Skip to content

Commit b95c53a

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents eb7f5bc + 0e046b5 commit b95c53a

File tree

30 files changed

+626
-772
lines changed

30 files changed

+626
-772
lines changed

cores/arduino/avr/pgmspace.h

Lines changed: 88 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
1-
/*
2-
pgmspace.h - Definitions for compatibility with AVR pgmspace macros
3-
4-
Copyright (c) 2015 Arduino LLC
5-
6-
Based on work of Paul Stoffregen on Teensy 3 (http://pjrc.com)
7-
8-
Permission is hereby granted, free of charge, to any person obtaining a copy
9-
of this software and associated documentation files (the "Software"), to deal
10-
in the Software without restriction, including without limitation the rights
11-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12-
copies of the Software, and to permit persons to whom the Software is
13-
furnished to do so, subject to the following conditions:
14-
15-
The above copyright notice and this permission notice shall be included in
16-
all copies or substantial portions of the Software.
17-
18-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24-
THE SOFTWARE
25-
*/
1+
/* Simple compatibility headers for AVR code used with ARM chips
2+
* Copyright (c) 2015 Paul Stoffregen <paul@pjrc.com>
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*/
2622

2723
#ifndef __PGMSPACE_H_
2824
#define __PGMSPACE_H_ 1
@@ -44,27 +40,91 @@ typedef int16_t prog_int16_t;
4440
typedef uint16_t prog_uint16_t;
4541
typedef int32_t prog_int32_t;
4642
typedef uint32_t prog_uint32_t;
43+
typedef int64_t prog_int64_t;
44+
typedef uint64_t prog_uint64_t;
4745

46+
#define memchr_P(str, c, len) memchr((str), (c), (len))
47+
#define memcmp_P(a, b, n) memcmp((a), (b), (n))
4848
#define memcpy_P(dest, src, num) memcpy((dest), (src), (num))
49-
#define strcpy_P(dest, src) strcpy((dest), (src))
49+
#define memmem_P(a, alen, b, blen) memmem((a), (alen), (b), (blen))
50+
#define memrchr_P(str, val, len) memrchr((str), (val), (len))
5051
#define strcat_P(dest, src) strcat((dest), (src))
52+
#define strchr_P(str, c) strchr((str), (c))
53+
#define strchrnul_P(str, c) strchrnul((str), (c))
5154
#define strcmp_P(a, b) strcmp((a), (b))
55+
#define strcpy_P(dest, src) strcpy((dest), (src))
56+
#define strcasecmp_P(a, b) strcasecmp((a), (b))
57+
#define strcasestr_P(a, b) strcasestr((a), (b))
58+
#define strlcat_P(dest, src, len) strlcat((dest), (src), (len))
59+
#define strlcpy_P(dest, src, len) strlcpy((dest), (src), (len))
60+
#define strlen_P(s) strlen((const char *)(s))
61+
#define strnlen_P(str, len) strnlen((str), (len))
62+
#define strncmp_P(a, b, n) strncmp((a), (b), (n))
63+
#define strncasecmp_P(a, b, n) strncasecmp((a), (b), (n))
64+
#define strncat_P(a, b, n) strncat((a), (b), (n))
65+
#define strncpy_P(a, b, n) strncpy((a), (b), (n))
66+
#define strpbrk_P(str, chrs) strpbrk((str), (chrs))
67+
#define strrchr_P(str, c) strrchr((str), (c))
68+
#define strsep_P(strp, delim) strsep((strp), (delim))
69+
#define strspn_P(str, chrs) strspn((str), (chrs))
5270
#define strstr_P(a, b) strstr((a), (b))
53-
#define strlen_P(a) strlen((a))
54-
#define sprintf_P(s, f, ...) sprintf((s), (f), __VA_ARGS__)
71+
#define sprintf_P(s, ...) sprintf((s), __VA_ARGS__)
72+
#define vfprintf_P(fp, s, ...) vfprintf((fp), (s), __VA_ARGS__)
73+
#define printf_P(...) printf(__VA_ARGS__)
74+
#define snprintf_P(s, n, ...) snprintf((s), (n), __VA_ARGS__)
75+
#define vsprintf_P(s, ...) vsprintf((s), __VA_ARGS__)
76+
#define vsnprintf_P(s, n, ...) vsnprintf((s), (n), __VA_ARGS__)
77+
#define fprintf_P(fp, ...) fprintf((fp), __VA_ARGS__)
78+
#define strlen_PF(a) strlen((a))
79+
#define strnlen_PF(src, len) strnlen((src), (len))
80+
#define memcpy_PF(dest, src, len) memcpy((dest), (src), (len))
81+
#define strcpy_PF(dest, src) strcpy((dest), (src))
82+
#define strncpy_PF(dest, src, len) strncpy((dest), (src), (len))
83+
#define strcat_PF(dest, src) strcat((dest), (src))
84+
#define strlcat_PF(dest, src, len) strlcat((dest), (src), (len))
85+
#define strncat_PF(dest, src, len) strncat((dest), (src), (len))
86+
#define strcmp_PF(s1, s2) strcmp((s1), (s2))
87+
#define strncmp_PF(s1, s2, n) strncmp((s1), (s2), (n))
88+
#define strcasecmp_PF(s1, s2) strcasecmp((s1), (s2))
89+
#define strncasecmp_PF(s1, s2, n) strncasecmp((s1), (s2), (n))
90+
#define strstr_PF(s1, s2) strstr((s1), (s2))
91+
#define strlcpy_PF(dest, src, n) strlcpy((dest), (src), (n))
92+
#define memcmp_PF(s1, s2, n) memcmp((s1), (s2), (n))
93+
5594

5695
#define pgm_read_byte(addr) (*(const unsigned char *)(addr))
96+
#if 0
5797
#define pgm_read_word(addr) (*(const unsigned short *)(addr))
5898
#define pgm_read_dword(addr) (*(const unsigned long *)(addr))
5999
#define pgm_read_float(addr) (*(const float *)(addr))
100+
#else
101+
#define pgm_read_word(addr) ({ \
102+
typeof(addr) _addr = (addr); \
103+
*(const unsigned short *)(_addr); \
104+
})
105+
#define pgm_read_dword(addr) ({ \
106+
typeof(addr) _addr = (addr); \
107+
*(const unsigned long *)(_addr); \
108+
})
109+
#define pgm_read_float(addr) ({ \
110+
typeof(addr) _addr = (addr); \
111+
*(const float *)(_addr); \
112+
})
113+
#define pgm_read_ptr(addr) ({ \
114+
typeof(addr) _addr = (addr); \
115+
*(void * const *)(_addr); \
116+
})
117+
#endif
60118

61119
#define pgm_read_byte_near(addr) pgm_read_byte(addr)
62120
#define pgm_read_word_near(addr) pgm_read_word(addr)
63121
#define pgm_read_dword_near(addr) pgm_read_dword(addr)
64122
#define pgm_read_float_near(addr) pgm_read_float(addr)
123+
#define pgm_read_ptr_near(addr) pgm_read_ptr(addr)
65124
#define pgm_read_byte_far(addr) pgm_read_byte(addr)
66125
#define pgm_read_word_far(addr) pgm_read_word(addr)
67126
#define pgm_read_dword_far(addr) pgm_read_dword(addr)
68127
#define pgm_read_float_far(addr) pgm_read_float(addr)
128+
#define pgm_read_ptr_far(addr) pgm_read_ptr(addr)
69129

70130
#endif

cores/arduino/pins_arduino.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,6 @@
2020

2121
#include "PeripheralPins.h"
2222

23-
/**
24-
* Libc porting layers
25-
*/
26-
#if defined ( __GNUC__ ) /* GCC CS3 */
27-
#include <syscalls.h> /** RedHat Newlib minimal stub */
28-
#define WEAK __attribute__ ((weak))
29-
#endif
30-
3123
// Arduino digital pin alias
3224
// GPIO port (A to K) * 16 pins: 176
3325
enum {

cores/arduino/pins_arduino_var.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,54 @@ uint32_t pinNametoDigitalPin(PinName p);
100100
(digitalPinFirstOccurence(p) == PIN_SERIAL_TX))
101101
#endif
102102

103+
// Default Definitions, could be redefined in variant.h
104+
#ifndef ADC_RESOLUTION
105+
#define ADC_RESOLUTION 12
106+
#endif
107+
#ifndef DACC_RESOLUTION
108+
#define DACC_RESOLUTION 12
109+
#endif
110+
#ifndef PWM_RESOLUTION
111+
#define PWM_RESOLUTION 8
112+
#endif
113+
#ifndef PWM_FREQUENCY
114+
#define PWM_FREQUENCY 1000
115+
#endif
116+
#ifndef PWM_MAX_DUTY_CYCLE
117+
#define PWM_MAX_DUTY_CYCLE 255
118+
#endif
119+
120+
// Default for Arduino connector compatibility
121+
// SPI Definitions
122+
#ifndef SS
123+
#define SS 10
124+
#endif
125+
#ifndef SS1
126+
#define SS1 4
127+
#endif
128+
#ifndef SS2
129+
#define SS2 7
130+
#endif
131+
#ifndef SS3
132+
#define SS3 8
133+
#endif
134+
#ifndef MOSI
135+
#define MOSI 11
136+
#endif
137+
#ifndef MISO
138+
#define MISO 12
139+
#endif
140+
#ifndef SCK
141+
#define SCK 13
142+
#endif
143+
// I2C Definitions
144+
#ifndef SDA
145+
#define SDA 14
146+
#endif
147+
#ifndef SCL
148+
#define SCL 15
149+
#endif
150+
103151
#ifdef __cplusplus
104152
}
105153
#endif

cores/arduino/stm32/interrupt.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
#include "stm32_def.h"
4444
#include "PinNames.h"
4545

46+
#if defined(STM32F3xx)
47+
#define EXTI2_IRQn EXTI2_TSC_IRQn
48+
#endif
49+
4650
#ifdef __cplusplus
4751
#include <functional>
4852

cores/arduino/stm32/stm32_def.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include "stm32_def.h"
2+
3+
#ifdef __cplusplus
4+
extern "C" {
5+
#endif
6+
7+
/**
8+
* @brief This function is executed in case of error occurrence.
9+
* @param None
10+
* @retval None
11+
*/
12+
WEAK void _Error_Handler(const char * msg, int val)
13+
{
14+
/* User can add his own implementation to report the HAL error return state */
15+
printf("Error: %s (%i)\n", msg, val);
16+
while(1)
17+
{
18+
}
19+
}
20+
21+
#ifdef __cplusplus
22+
}
23+
#endif

cores/arduino/stm32/stm32_def.h

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,34 +51,29 @@
5151
#endif
5252

5353
// Here define some compatibility
54-
#ifdef STM32F0xx
55-
56-
#elif defined(STM32F1xx)
57-
58-
#elif defined(STM32F2xx)
59-
60-
#elif defined(STM32F3xx)
61-
#define EXTI2_IRQn EXTI2_TSC_IRQn
62-
#elif defined(STM32F4xx)
63-
64-
#elif defined(STM32F7xx)
65-
66-
#elif defined(STM32L0xx)
67-
68-
#elif defined(STM32L1xx)
69-
70-
#elif defined(STM32L4xx)
71-
#endif
72-
7354
#ifndef CAN1
7455
#define CAN1 CAN
7556
#endif
7657

58+
/**
59+
* Libc porting layers
60+
*/
61+
#if defined ( __GNUC__ ) /* GCC CS3 */
62+
#include <syscalls.h> /** RedHat Newlib minimal stub */
63+
#define WEAK __attribute__ ((weak))
64+
#endif
65+
7766
#ifdef __cplusplus
7867
extern "C"{
7968
#endif // __cplusplus
69+
8070
// weaked functions declaration
8171
void SystemClock_Config(void);
72+
73+
void _Error_Handler(const char *, int);
74+
75+
#define Error_Handler() _Error_Handler(__FILE__, __LINE__)
76+
8277
#ifdef __cplusplus
8378
} // extern "C"
8479
#endif // __cplusplus

libraries/SPI/README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
## SPI
2+
3+
STM32 SPI library has been modified with the possibility to manage several CS pins without to stop the SPI interface.
4+
_We do not describe here the [SPI Arduino API](https://www.arduino.cc/en/Reference/SPI) but the functionalities added._
5+
6+
We give to the user 3 possiblities about the management of the CS pin:
7+
1. the CS pin is managed directly by the user code before to transfer the data (like the Arduino SPI library)
8+
2. the user gives the CS pin number to the library API and the library manages itself the CS pin (see example below)
9+
3. the user uses a hardware CS pin linked to the SPI peripheral
10+
11+
### New API functions
12+
13+
* **`SPIClass::SPIClass(uint8_t mosi, uint8_t miso, uint8_t sclk, uint8_t ssel)`**: alternative class constructor
14+
_Params_ SPI mosi pin
15+
_Params_ SPI miso pin
16+
_Params_ SPI sclk pin
17+
_Params_ (optional) SPI ssel pin. This pin must be an hardware CS pin. If you configure this pin, the chip select will be managed by the SPI peripheral. Do not use API functions with CS pin in parameter.
18+
19+
* **`void SPIClass::begin(uint8_t _pin)`**: initialize the SPI interface and add a CS pin
20+
_Params_ spi CS pin to be managed by the SPI library
21+
22+
* **`void beginTransaction(uint8_t pin, SPISettings settings)`**: allows to configure the SPI with other parameter. These new parameter are saved this an associated CS pin.
23+
_Params_ SPI CS pin to be managed by the SPI library
24+
_Params_ SPI settings
25+
26+
* **`void endTransaction(uint8_t pin)`**: removes a CS pin and the SPI settings associated
27+
_Params_ SPI CS pin managed by the SPI library
28+
29+
**_Note 1_** The following functions must be called after initialization of the SPI instance with `begin()` or `beginTransaction()`.
30+
If you have several device to manage, you can call `beginTransaction()` several time with different CS pin in parameter.
31+
Then you can call the following functions with different CS pin without call again `beginTransaction()` (until you call `end()` or `endTransaction()`).
32+
33+
**_Note 2_** If the mode is set to `SPI_CONTINUE`, the CS pin is kept enabled. Be careful in case you use several CS pin.
34+
35+
* **`byte transfer(uint8_t pin, uint8_t _data, SPITransferMode _mode = SPI_LAST)`**: write/read one byte
36+
_Params_ SPI CS pin managed by the SPI library
37+
_Params_ data to write
38+
_Params_ (optional) if `SPI_LAST` CS pin is reset, `SPI_CONTINUE` the CS pin is kept enabled.
39+
_Return_ byte received
40+
41+
* **`uint16_t transfer16(uint8_t pin, uint16_t _data, SPITransferMode _mode = SPI_LAST)`**: write/read half-word
42+
_Params_ SPI CS pin managed by the SPI library
43+
_Params_ 16bits data to write
44+
_Params_ (optional) if `SPI_LAST` CS pin is reset, `SPI_CONTINUE` the CS pin is kept enabled.
45+
_Return_ 16bits data received
46+
47+
* **`void transfer(uint8_t pin, void *_buf, size_t _count, SPITransferMode _mode = SPI_LAST)`**: write/read several bytes. Only one buffer used to write and read the data
48+
_Params_ SPI CS pin managed by the SPI library
49+
_Params_ pointer to data to write. The data will be replaced by the data read.
50+
_Params_ number of data to write/read.
51+
_Params_ (optional) if `SPI_LAST` CS pin is reset, `SPI_CONTINUE` the CS pin is kept enabled.
52+
53+
* **`void transfer(byte _pin, void *_bufout, void *_bufin, size_t _count, SPITransferMode _mode = SPI_LAST)`**: write/read several bytes. One buffer for the output data and one for the input data
54+
_Params_ SPI CS pin managed by the SPI library
55+
_Params_ pointer to data to write.
56+
_Params_ pointer where to store the data read.
57+
_Params_ number of data to write/read.
58+
_Params_ (optional) if `SPI_LAST` CS pin is reset, `SPI_CONTINUE` the CS pin is kept enabled.
59+
60+
### Example
61+
62+
This is an example of the use of the CS pin management:
63+
64+
```C++
65+
SPI.begin(2); //Enables the SPI instance with default settings and attachs the CS pin
66+
SPI.beginTransaction(1, settings); //Attachs another CS pin and configure the SPI instance with other settings
67+
SPI.transfer(1, 0x52); //Transfers data to the first device
68+
SPI.transfer(2, 0xA4); //Transfers data to the second device. The SPI instance is configured with the right settings
69+
SPI.end() //SPI instance is disabled
70+
```

0 commit comments

Comments
 (0)