Skip to content

Commit 22fad75

Browse files
committed
Merge remote-tracking branch 'refs/remotes/rogerclarkmelbourne/master'
2 parents e7456e1 + 71a198a commit 22fad75

46 files changed

Lines changed: 1781 additions & 60 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Use of these files is at your own risk.
99

1010

1111
##Summary:
12-
This repo contains, the "Hardware" files to support STM32 based boards on Arduino version 1.6.4 and 1.6.5, and 1.6.9 including [LeafLabs Maple, and Maple mini](http://www.leaflabs.com/about-maple/), and other generic STM32F103 boards
12+
This repo contains, the "Hardware" files to support STM32 based boards on Arduino version 1.6.13 or 1.6.12 (some older versions may also work) including [LeafLabs Maple, and Maple mini](http://www.leaflabs.com/about-maple/), and other generic STM32F103 boards
1313

1414
***PRIMARY SUPPORT FORUM: http://www.stm32duino.com/***
1515

STM32F1/boards.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,3 +580,34 @@ genericGD32F103C.menu.cpu_speed.speed_96mhz.build.f_cpu=96000000L
580580

581581
genericGD32F103C.menu.cpu_speed.speed_72mhz=72Mhz (compatibility)
582582
genericGD32F103C.menu.cpu_speed.speed_72mhz.build.f_cpu=72000000L
583+
584+
########################### STM32VLD to FLASH ###########################
585+
586+
STM32VLD.name=STM32VLD to FLASH
587+
#STM32VLD.vid.0=0x1EAF
588+
#STM32VLD.pid.0=0x0004
589+
590+
STM32VLD.build.vect=VECT_TAB_ADDR=0x8000000
591+
STM32VLD.build.core=maple
592+
STM32VLD.build.board=STM32VLD
593+
STM32VLD.build.variant=STM32VLD
594+
STM32VLD.build.ldscript=ld/jtag.ld
595+
596+
STM32VLD.build.family=cortex-m3
597+
STM32VLD.build.f_cpu=24000000L
598+
STM32VLD.upload.use_1200bps_touch=false
599+
STM32VLD.upload.file_type=bin
600+
STM32VLD.upload.auto_reset=true
601+
STM32VLD.upload.params.quiet=no
602+
603+
STM32VLD.build.cpu_flags=-DMCU_STM32F100RB
604+
##---------------------------- UPLOAD METHODS ---------------------------
605+
606+
607+
STM32VLD.menu.upload_method.STLinkMethod=STLink
608+
STM32VLD.menu.upload_method.STLinkMethod.upload.protocol=STLink
609+
STM32VLD.menu.upload_method.STLinkMethod.upload.tool=stlink_upload
610+
STM32VLD.menu.upload_method.STLinkMethod.build.upload_flags=-DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG
611+
612+
613+
################################################################################

STM32F1/cores/maple/Print.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,7 @@ size_t Print::print(double n, int digits) {
126126

127127
size_t Print::print(const __FlashStringHelper *ifsh)
128128
{
129-
size_t n = print(ifsh);
130-
n += println();
131-
return n;
129+
return print(reinterpret_cast<const char *>(ifsh));
132130
}
133131

134132
size_t Print::print(const Printable& x)

STM32F1/cores/maple/io.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,6 @@ uint16 analogRead(uint8 pin);
160160
*/
161161
void shiftOut(uint8 dataPin, uint8 clockPin, uint8 bitOrder, uint8 value);
162162

163+
uint32 shiftIn( uint32 ulDataPin, uint32 ulClockPin, uint32 ulBitOrder );
164+
163165
#endif

STM32F1/cores/maple/new.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright (c) 2014 Arduino. All right reserved.
3+
4+
This library is free software; you can redistribute it and/or
5+
modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either
7+
version 2.1 of the License, or (at your option) any later version.
8+
9+
This library is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
See the GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with this library; if not, write to the Free Software
16+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
#include <stdlib.h>
20+
21+
void *operator new(size_t size) {
22+
return malloc(size);
23+
}
24+
25+
void *operator new[](size_t size) {
26+
return malloc(size);
27+
}
28+
29+
void operator delete(void * ptr) {
30+
free(ptr);
31+
}
32+
33+
void operator delete[](void * ptr) {
34+
free(ptr);
35+
}
36+

STM32F1/cores/maple/tone.cpp

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
///////////////////////////////////////////////////////////////////////
2+
//
3+
// tone(pin,frequency[,duration]) generate a tone on a given pin
4+
//
5+
// noTone(pin) switch off the tone on the pin
6+
//
7+
// setToneTimerChannel(timer,channel) force use of given timer/channel
8+
//
9+
///////////////////////////////////////////////////////////////////////
10+
11+
#include "Arduino.h"
12+
#include <HardwareTimer.h>
13+
14+
15+
#define PinTimer(pin) (PIN_MAP[pin].timer_device->clk_id-RCC_TIMER1+1)
16+
#define PinChannel(pin) (PIN_MAP[pin].timer_channel)
17+
18+
// if USE_PIN_TIMER is set, the PWM timer/channel is used for PWM pins
19+
#define USE_PIN_TIMER
20+
21+
// if USE_BSRR is set the tone pin will be written via the fast BSRR register
22+
// instead of using the slow digitalWrite() function in the interrupt handler
23+
#define USE_BSRR
24+
25+
// construct static timer array (
26+
27+
28+
#ifdef STM32_HIGH_DENSITY
29+
// define default timer and channel
30+
#ifndef TONE_TIMER
31+
#define TONE_TIMER 8
32+
#endif
33+
#ifndef TONE_CHANNEL
34+
#define TONE_CHANNEL 8
35+
#endif
36+
37+
HardwareTimer TTimer1(1), TTimer2(2), TTimer3(3), TTimer4(4),TTimer5(5), TTimer6(6), TTimer7(7), TTimer8(8);
38+
HardwareTimer *TTimer[8] = { &TTimer1,&TTimer2,&TTimer3,&TTimer4,&TTimer5,&TTimer6,&TTimer7,&TTimer8 };
39+
#else
40+
// define default timer and channel
41+
#ifndef TONE_TIMER
42+
#define TONE_TIMER 4
43+
#endif
44+
#ifndef TONE_CHANNEL
45+
#define TONE_CHANNEL 4
46+
#endif
47+
48+
HardwareTimer TTimer1(1), TTimer2(2), TTimer3(3), TTimer4(4);
49+
HardwareTimer *TTimer[4] = { &TTimer1,&TTimer2,&TTimer3,&TTimer4 };
50+
#endif
51+
52+
53+
uint8_t tone_force_channel = 0; // forced timer channel
54+
uint8_t tone_force_ntimer = 0; // forced timer
55+
56+
HardwareTimer *tone_timer;// = TTimer[TONE_TIMER-1]; // timer used to generate frequency
57+
uint8_t tone_channel = TONE_CHANNEL; // timer channel used to generate frequency
58+
uint8_t tone_ntimer = TONE_TIMER; // timer used to generate frequency
59+
60+
bool tone_state = true; // last pin state for toggling
61+
short tone_pin = -1; // pin for outputting sound
62+
short tone_freq = 444; // tone frequency (0=pause)
63+
uint32_t tone_nhw = 0; // tone duration in number of half waves
64+
uint16_t tone_tcount = 0; // time between handler calls in 1/36 usec
65+
uint16_t tone_ncount = 0; // handler call between toggling
66+
uint16_t tone_n = 0; // remaining handler calls before toggling
67+
uint32_t tone_next = 0; // counter value of next interrupt
68+
69+
#ifdef USE_BSRR
70+
volatile uint32_t *tone_bsrr; // BSRR set register (lower 16 bits)
71+
uint32_t tone_smask=0; // BSRR set bitmask
72+
uint32_t tone_rmask=0; // BSRR reset bitmask
73+
#endif
74+
75+
76+
////////////////////////////////////////////////////////////////////////////////
77+
// timer hander for tone with no duration specified,
78+
// will keep going until noTone() is called
79+
void tone_handler_1(void) {
80+
tone_next += tone_tcount; // comparator value for next interrupt
81+
tone_timer->setCompare(tone_channel, tone_next); // and install it
82+
if(--tone_n == 0){
83+
tone_state = !tone_state; // toggle tone output
84+
85+
#ifdef USE_BSRR
86+
if(tone_state)
87+
*tone_bsrr = tone_smask;
88+
else
89+
*tone_bsrr = tone_rmask;
90+
#else
91+
digitalWrite(tone_pin,tone_state);// and output it
92+
#endif
93+
94+
tone_n = tone_ncount; // reset interrupt counter
95+
}
96+
}
97+
98+
////////////////////////////////////////////////////////////////////////////////
99+
// timer hander for tone with a specified duration,
100+
// will stop automatically when duration time is up.
101+
void tone_handler_2(void) {
102+
tone_next += tone_tcount;
103+
tone_timer->setCompare(tone_channel, tone_next);
104+
if(--tone_n == 0){
105+
if(tone_freq>0){ // toggle pin
106+
tone_state = !tone_state;
107+
#ifdef USE_BSRR
108+
if(tone_state)
109+
*tone_bsrr = tone_smask;
110+
else
111+
*tone_bsrr = tone_rmask;
112+
#else
113+
digitalWrite(tone_pin,tone_state);// and output it
114+
#endif
115+
}
116+
tone_n = tone_ncount;
117+
if(!--tone_nhw){ // check if tone duration has finished
118+
tone_timer->pause(); // disable timer
119+
pinMode(tone_pin, INPUT); // disable tone pin
120+
}
121+
}
122+
}
123+
124+
////////////////////////////////////////////////////////////////////////////////
125+
// play a tone on given pin with given frequency and optional duration in msec
126+
void tone(uint32_t pin, uint32_t freq, uint32_t duration) {
127+
tone_pin = pin;
128+
129+
#ifdef USE_PIN_TIMER
130+
// if the pin has a PWM timer/channel, use it (unless the timer/channel are forced)
131+
if(PinChannel(tone_pin) && !tone_force_channel){
132+
tone_channel = PinChannel(tone_pin);
133+
tone_ntimer = PinTimer(tone_pin);
134+
} else
135+
#endif
136+
{
137+
// set timer and channel to default resp values forced with setToneTimerChannel
138+
tone_ntimer = tone_force_channel?tone_force_ntimer:TONE_TIMER;
139+
tone_channel = tone_force_channel?tone_force_channel:TONE_CHANNEL;
140+
}
141+
142+
tone_timer = TTimer[tone_ntimer-1];
143+
tone_freq = freq;
144+
tone_nhw = 0;
145+
tone_next = 0;
146+
147+
tone_timer->pause();
148+
149+
if(freq > 0 && duration >0 ){
150+
uint32_t count = 18000000/freq; // timer counts per half wave
151+
tone_ncount = tone_n = (count>>16)+1; // number of 16-bit count chunk
152+
tone_tcount = count/tone_ncount; // size of count chunk
153+
if(duration > 0) // number of half waves to be generated
154+
tone_nhw = ((duration*(freq>0?freq:100))/1000)<<1;
155+
else // no duration specified, continuous sound until noTone() called
156+
tone_nhw = 0;
157+
158+
pinMode(tone_pin, PWM); // configure output pin
159+
pinMode(tone_pin, OUTPUT); // configure output pin
160+
161+
#ifdef USE_BSRR
162+
// Set up BSRR register values for fast ISR
163+
tone_bsrr = &((PIN_MAP[tone_pin].gpio_device)->regs->BSRR);
164+
tone_smask = (BIT(PIN_MAP[tone_pin].gpio_bit));
165+
tone_rmask = tone_smask<<16;
166+
#endif
167+
168+
// Set up an interrupt on given timer and channel
169+
tone_next = tone_tcount; // prepare channel compare register
170+
tone_timer->setMode(tone_channel,TIMER_OUTPUT_COMPARE);
171+
tone_timer->setCompare(tone_channel,tone_next);
172+
// attach corresponding handler routine
173+
tone_timer->attachInterrupt(tone_channel,tone_nhw?tone_handler_2:tone_handler_1);
174+
175+
// Refresh the tone timer
176+
tone_timer->refresh();
177+
178+
// Start the timer counting
179+
tone_timer->resume();
180+
181+
} else {
182+
183+
// detach handler routine
184+
tone_timer->detachInterrupt(tone_channel);
185+
// disactive pin by configuring it as input
186+
pinMode(tone_pin, INPUT);
187+
188+
}
189+
}
190+
191+
////////////////////////////////////////////////////////////////////////////////
192+
// disable tone on specified pin, if any
193+
void noTone(uint32_t pin){
194+
tone(pin,0,0); // it's all handled in tone()
195+
}
196+
197+
////////////////////////////////////////////////////////////////////////////////
198+
// set timer and channel to some different value
199+
// must be called before calling tone() or after noTone() was called
200+
void setToneTimerChannel(uint8_t ntimer, uint8_t channel){
201+
tone_force_ntimer = ntimer;
202+
tone_force_channel = channel;
203+
}

STM32F1/cores/maple/tone.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
Copyright (c) 2015 Arduino LLC. All right reserved.
3+
4+
This library is free software; you can redistribute it and/or
5+
modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either
7+
version 2.1 of the License, or (at your option) any later version.
8+
9+
This library is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
See the GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with this library; if not, write to the Free Software
16+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
#pragma once
20+
21+
#ifdef __cplusplus
22+
23+
#include "Arduino.h"
24+
25+
void tone(uint32_t _pin, uint32_t frequency, uint32_t duration = 0);
26+
void noTone(uint32_t _pin);
27+
28+
#endif

STM32F1/cores/maple/wirish.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
#include <stdint.h>
7777

7878
#include <WCharacter.h>
79+
#include <tone.h>
7980

8081
typedef unsigned int word;
8182
// typedef uint16 word;// definition from Arduino website, now appears to be incorrect for 32 bit devices

STM32F1/cores/maple/wirish_shift.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,28 @@ void shiftOut(uint8 dataPin, uint8 clockPin, uint8 bitOrder, uint8 value) {
3535
gpio_toggle_bit(PIN_MAP[clockPin].gpio_device, PIN_MAP[clockPin].gpio_bit);// togglePin(clockPin);
3636
}
3737
}
38+
39+
uint32_t shiftIn( uint32_t ulDataPin, uint32_t ulClockPin, uint32_t ulBitOrder )
40+
{
41+
uint8_t value = 0 ;
42+
uint8_t i ;
43+
44+
45+
for ( i=0 ; i < 8 ; ++i )
46+
{
47+
digitalWrite( ulClockPin, HIGH ) ;
48+
49+
if ( ulBitOrder == LSBFIRST )
50+
{
51+
value |= digitalRead( ulDataPin ) << i ;
52+
}
53+
else
54+
{
55+
value |= digitalRead( ulDataPin ) << (7 - i) ;
56+
}
57+
58+
digitalWrite( ulClockPin, LOW ) ;
59+
}
60+
61+
return value ;
62+
}

STM32F1/libraries/A_STM32_Examples/examples/General/InternalTempSensor/InternalTempSensor.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void setup_temperature_sensor() {
1919
// temperature sensor from power down mode. Do this first 'cause according to
2020
// the Datasheet section 5.3.21 it takes from 4 to 10 uS to power up the sensor.
2121

22-
regs->CR2 |= ADC_CR2_TSEREFE;
22+
regs->CR2 |= ADC_CR2_TSVREFE;
2323

2424
// 2. Select a sample time of 17.1 μs
2525
// set channel 16 sample time to 239.5 cycles

0 commit comments

Comments
 (0)