Skip to content

Commit 482440e

Browse files
Arduino Zero sync, add new HCLK/APB1/APB2 clock scheme
1 parent 65508a6 commit 482440e

29 files changed

+723
-458
lines changed

boards.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ dragonfly.build.core=stm32l4
2929
dragonfly.build.extra_flags=-DSTM32L476xx -D__FPU_PRESENT=1 -march=armv7e-m -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mabi=aapcs -mslow-flash-data -fsingle-precision-constant
3030
dragonfly.build.ldscript=linker_scripts/flash.ld
3131
dragonfly.build.variant=dragonfly
32-
dragonfly.build.variant_system_lib=stm32l4_dragonfly
33-
dragonfly.build.variant_system_include="-I{runtime.platform.path}/system/libstm32l4_dragonfly/CMSIS/Include" "-I{runtime.platform.path}/system/libstm32l4_dragonfly/CMSIS/Device/ST/STM32L4xx/Include" "-I{runtime.platform.path}/system/libstm32l4_dragonfly/USB/HAL/Inc" "-I{runtime.platform.path}/system/libstm32l4_dragonfly/USB/Core/Inc" "-I{runtime.platform.path}/system/libstm32l4_dragonfly/USB/Class/CDC/Inc" "-I{runtime.platform.path}/system/libstm32l4_dragonfly/USB/Class/MSC/Inc" "-I{runtime.platform.path}/system/libstm32l4_dragonfly/USB" "-I{runtime.platform.path}/system/libstm32l4_dragonfly"
32+
dragonfly.build.variant_system_libs="-L{runtime.platform.path}/system/libstm32l4" "-L{runtime.platform.path}/system/libstm32l4/CMSIS/Lib" -lstm32l4 -larm_cortexM4lf_math
33+
dragonfly.build.variant_system_include="-I{runtime.platform.path}/system/libstm32l4/CMSIS/Include" "-I{runtime.platform.path}/system/libstm32l4/CMSIS/Device/ST/STM32L4xx/Include" "-I{runtime.platform.path}/system/libstm32l4/USB/HAL/Inc" "-I{runtime.platform.path}/system/libstm32l4/USB/Core/Inc" "-I{runtime.platform.path}/system/libstm32l4/USB/Class/CDC/Inc" "-I{runtime.platform.path}/system/libstm32l4/USB/Class/MSC/Inc" "-I{runtime.platform.path}/system/libstm32l4/USB" "-I{runtime.platform.path}/system/libstm32l4"
3434
dragonfly.build.vid=0x1209
3535
dragonfly.build.pid=0x6667
3636

@@ -48,3 +48,11 @@ dragonfly.menu.CpuFrequency.24=24 MHz
4848
dragonfly.menu.CpuFrequency.24.build.f_cpu=24000000L
4949
dragonfly.menu.CpuFrequency.16=16 MHz
5050
dragonfly.menu.CpuFrequency.16.build.f_cpu=16000000L
51+
dragonfly.menu.CpuFrequency.8=8 MHz
52+
dragonfly.menu.CpuFrequency.8.build.f_cpu=8000000L
53+
dragonfly.menu.CpuFrequency.4=4 MHz
54+
dragonfly.menu.CpuFrequency.4.build.f_cpu=4000000L
55+
dragonfly.menu.CpuFrequency.2=2 MHz
56+
dragonfly.menu.CpuFrequency.2.build.f_cpu=2000000L
57+
dragonfly.menu.CpuFrequency.1=1 MHz
58+
dragonfly.menu.CpuFrequency.1.build.f_cpu=1000000L

cores/stm32l4/Arduino.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ typedef uint16_t word;
3535
//
3636
#include "avr/pgmspace.h"
3737
#include "avr/interrupt.h"
38+
#include "avr/io.h"
3839

3940
#include "binary.h"
40-
#include "stdlib_noniso.h"
41+
#include "itoa.h"
4142

4243
#ifdef __cplusplus
4344
extern "C"{
@@ -49,6 +50,8 @@ extern "C"{
4950
#undef SPI1
5051
#undef SPI2
5152

53+
#define F_CPU SystemCoreClock
54+
5255
#include "wiring_constants.h"
5356

5457
#define clockCyclesPerMicrosecond() ( SystemCoreClock / 1000000L )
@@ -77,7 +80,9 @@ void loop( void ) ;
7780
#include "STM32.h"
7881
#endif
7982
#ifdef __cplusplus
83+
#if defined(STM32L4_CONFIG_USBD_CDC)
8084
#include "CDC.h"
85+
#endif /* STM32L4_CONFIG_USBD_CDC */
8186
#include "Uart.h"
8287
#endif
8388

@@ -87,9 +92,9 @@ void loop( void ) ;
8792
#include "wiring.h"
8893
#include "wiring_analog.h"
8994
#include "wiring_digital.h"
95+
#include "wiring_interrupts.h"
9096
#include "wiring_pulse.h"
9197
#include "wiring_shift.h"
92-
#include "WInterrupts.h"
9398

9499
// undefine stdlib's abs if encountered
95100
#ifdef abs

cores/stm32l4/CDC.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@
2626
* WITH THE SOFTWARE.
2727
*/
2828

29-
#include "CDC.h"
3029
#include "Arduino.h"
30+
#include "CDC.h"
3131
#include "wiring_private.h"
3232

33+
#if defined(STM32L4_CONFIG_USBD_CDC)
34+
3335
/* STM32L4x5/STM32L4x6 have USB_OTG_FS with a multi-packet FIFO. However
3436
* to avoid sending ZLP packets, the CDC_TX_PACKET_SIZE is one byte
3537
* less than the maximum FIFO size in terms of 64 byte packets.
@@ -494,3 +496,6 @@ extern void serialEvent() __attribute__((weak));
494496
bool SerialUSB_empty() { return !SerialUSB.available(); }
495497

496498
CDC SerialUSB(&stm32l4_usbd_cdc, (serialEvent != NULL));
499+
500+
#endif /* STM32L4_CONFIG_USBD_CDC */
501+

cores/stm32l4/Makefile

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,38 @@ ASFLAGS = -c -g -x assembler-with-cpp $(EXTRAS) $(DEFINES) $(INCLUDES)
1111
LDFLAGS = -L../../variants/dragonfly -Os -Wl,--gc-sections -save-temps $(EXTRAS) -T../../variants/dragonfly/linker_scripts/flash.ld --specs=nano.specs -mcpu=cortex-m4 -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align
1212
WARNINGS = -Wall -Wextra -Wno-unused-parameter
1313
EXTRAS = -DSTM32L476xx -D__FPU_PRESENT=1 -march=armv7e-m -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mabi=aapcs -mslow-flash-data
14-
DEFINES = -DF_CPU=80000000L -DARDUINO=10606 -D_ARDUINO_STM32L4_DRAGONFLY -DARDUINO_ARCH_STM32L4
14+
DEFINES = -D_SYSTEM_CORE_CLOCK_=80000000L -DARDUINO=10606 -D_ARDUINO_STM32L4_DRAGONFLY -DARDUINO_ARCH_STM32L4
1515
INCLUDES = -I../../system/libstm32l4_dragonfly/CMSIS/Include -I../../system/libstm32l4_dragonfly/CMSIS/Device/ST/STM32L4xx/Include -I../../system/libstm32l4_dragonfly/USB/HAL/Inc -I../../system/libstm32l4_dragonfly/USB/Core/Inc -I../../system/libstm32l4_dragonfly/USB/Class/CDC/Inc -I../../system/libstm32l4_dragonfly/USB/Class/MSC/Inc -I../../system/libstm32l4_dragonfly/USB -I../../system/libstm32l4_dragonfly/ -I../../variants/dragonfly -I../../libraries/SPI/ -I../../libraries/Wire/ -I../../libraries/Servo/src/ -I.
1616

1717
SRCS = \
1818
../../libraries/Servo/src/Servo.cpp \
1919
../../libraries/SPI/SPI.cpp \
2020
../../libraries/Wire/Wire.cpp \
2121
../../variants/dragonfly/variant.cpp \
22+
avr/dtostrf.c \
2223
avr/eeprom.c \
24+
avr/fdevopen.c \
2325
CDC.cpp \
2426
FS.cpp \
2527
HardwareSerial.cpp \
2628
IPAddress.cpp \
2729
Print.cpp \
28-
Reset.cpp \
2930
RingBuffer.cpp \
3031
STM32.cpp \
3132
Stream.cpp \
3233
Tone.cpp \
3334
Uart.cpp \
34-
WInterrupts.c \
3535
WMath.cpp \
3636
WString.cpp \
3737
abi.cpp \
3838
hooks.c \
39+
itoa.c \
3940
main.cpp \
4041
new.cpp \
41-
stdlib_noniso.c \
4242
wiring.c \
4343
wiring_analog.c \
4444
wiring_digital.c \
45+
wiring_interrupts.c \
4546
wiring_pulse.c \
4647
wiring_shift.c
4748

@@ -50,29 +51,30 @@ OBJS = \
5051
../../libraries/SPI/SPI.o \
5152
../../libraries/Wire/Wire.o \
5253
../../variants/dragonfly/variant.o \
54+
avr/dtostrf.o \
5355
avr/eeprom.o \
56+
avr/fdevopen.o \
5457
CDC.o \
5558
FS.o \
5659
HardwareSerial.o \
5760
IPAddress.o \
5861
Print.o \
59-
Reset.o \
6062
RingBuffer.o \
6163
STM32.o \
6264
Stream.o \
6365
Tone.o \
6466
Uart.o \
65-
WInterrupts.o \
6667
WMath.o \
6768
WString.o \
6869
abi.o \
6970
hooks.o \
71+
itoa.o \
7072
main.o \
7173
new.o \
72-
stdlib_noniso.o \
7374
wiring.o \
7475
wiring_analog.o \
7576
wiring_digital.o \
77+
wiring_interrupts.o \
7678
wiring_pulse.o \
7779
wiring_shift.o
7880

cores/stm32l4/Print.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ size_t Print::printFloat(double number, uint8_t digits)
245245
while (digits-- > 0)
246246
{
247247
remainder *= 10.0;
248-
int toPrint = int(remainder);
248+
unsigned int toPrint = (unsigned int)remainder;
249249
n += print(toPrint);
250250
remainder -= toPrint;
251251
}

cores/stm32l4/RingBuffer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class RingBuffer
3131
{
3232
public:
3333
uint8_t _aucBuffer[SERIAL_BUFFER_SIZE] ;
34-
volatile uint16_t _iHead ;
35-
volatile uint16_t _iTail ;
34+
int _iHead ;
35+
int _iTail ;
3636

3737
public:
3838
RingBuffer( void ) ;

cores/stm32l4/Stream.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class Stream : public Print
6868
// parsing methods
6969

7070
void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second
71+
unsigned long getTimeout(void) { return _timeout; }
7172

7273
bool find(char *target); // reads data from the stream until the target string is found
7374
bool find(uint8_t *target) { return find ((char *)target); }

cores/stm32l4/WString.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
*/
2121

2222
#include "WString.h"
23-
#include "stdlib_noniso.h"
23+
#include "itoa.h"
24+
#include "avr/dtostrf.h"
2425

2526
/*********************************************/
2627
/* Constructors */
@@ -194,7 +195,7 @@ String & String::copy(const __FlashStringHelper *pstr, unsigned int length)
194195
void String::move(String &rhs)
195196
{
196197
if (buffer) {
197-
if (capacity >= rhs.len) {
198+
if (rhs && capacity >= rhs.len) {
198199
strcpy(buffer, rhs.buffer);
199200
len = rhs.len;
200201
rhs.len = 0;
@@ -741,6 +742,11 @@ long String::toInt(void) const
741742

742743
float String::toFloat(void) const
743744
{
744-
if (buffer) return float(atof(buffer));
745+
return float(toDouble());
746+
}
747+
748+
double String::toDouble(void) const
749+
{
750+
if (buffer) return atof(buffer);
745751
return 0;
746752
}

cores/stm32l4/WString.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,12 @@ class String
159159
char& operator [] (unsigned int index);
160160
void getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index=0) const;
161161
void toCharArray(char *buf, unsigned int bufsize, unsigned int index=0) const
162-
{getBytes((unsigned char *)buf, bufsize, index);}
163-
const char * c_str() const { return buffer; }
164-
const char* begin() { return c_str(); }
165-
const char* end() { return c_str() + length(); }
162+
{ getBytes((unsigned char *)buf, bufsize, index); }
163+
const char* c_str() const { return buffer; }
164+
char* begin() { return buffer; }
165+
char* end() { return buffer + length(); }
166+
const char* begin() const { return c_str(); }
167+
const char* end() const { return c_str() + length(); }
166168

167169
// search
168170
int indexOf( char ch ) const;
@@ -188,6 +190,7 @@ class String
188190
// parsing/conversion
189191
long toInt(void) const;
190192
float toFloat(void) const;
193+
double toDouble(void) const;
191194

192195
protected:
193196
char *buffer; // the actual char array

cores/stm32l4/avr/io.h

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
/*
2-
* Copyright (c) 2016 Thomas Roell. All rights reserved.
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
6-
* deal with the Software without restriction, including without limitation the
7-
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8-
* sell 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-
* 1. Redistributions of source code must retain the above copyright notice,
12-
* this list of conditions and the following disclaimers.
13-
* 2. Redistributions in binary form must reproduce the above copyright
14-
* notice, this list of conditions and the following disclaimers in the
15-
* documentation and/or other materials provided with the distribution.
16-
* 3. Neither the name of Thomas Roell, nor the names of its contributors
17-
* may be used to endorse or promote products derived from this Software
18-
* without specific prior written permission.
19-
*
20-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23-
* CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25-
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26-
* WITH THE SOFTWARE.
27-
*/
28-
29-
#ifndef _AVR_IO_H_
30-
#define _AVR_IO_H_
31-
32-
#define E2END 0x3ff
33-
34-
#endif /* _AVR_IO_H_ */
2+
io.h - Definitions for compatibility with AVR io macros
3+
4+
Copyright (c) 2016 Arduino LLC
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
THE SOFTWARE
23+
*/
24+
25+
#ifndef _IO_H_
26+
#define _IO_H_
27+
28+
#define RAMSTART 0x20000000
29+
#define RAMSIZE (96 * 1024)
30+
#define RAMEND (RAMSTART + RAMSIZE - 1)
31+
32+
#define E2END 0x3ff
33+
34+
#endif

cores/stm32l4/hooks.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,30 @@ static void __empty() {
2929
// Empty
3030
}
3131
void yield(void) __attribute__ ((weak, alias("__empty")));
32+
33+
/**
34+
* SysTick hook
35+
*
36+
* This function is called from SysTick handler, before the default
37+
* handler provided by Arduino.
38+
*/
39+
static int __false() {
40+
// Return false
41+
return 0;
42+
}
43+
int sysTickHook(void) __attribute__ ((weak, alias("__false")));
44+
45+
/**
46+
* SVC hook
47+
* PendSV hook
48+
*
49+
* These functions are called from SVC handler, and PensSV handler.
50+
* Default action is halting.
51+
*/
52+
static void __halt() {
53+
// Halts
54+
while (1)
55+
;
56+
}
57+
void svcHook(void) __attribute__ ((weak, alias("__halt")));
58+
void pendSVHook(void) __attribute__ ((weak, alias("__halt")));

0 commit comments

Comments
 (0)