Skip to content

Commit 073aa23

Browse files
committed
Merge remote-tracking branch 'refs/remotes/rogerclarkmelbourne/master'
2 parents d0c5a95 + 6bbb5dc commit 073aa23

File tree

38 files changed

+1367
-49
lines changed

38 files changed

+1367
-49
lines changed

STM32F1/boards.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,12 @@ genericSTM32F103C.menu.upload_method.BMPMethod.upload.protocol=gdb_bmp
211211
genericSTM32F103C.menu.upload_method.BMPMethod.upload.tool=bmp_upload
212212
genericSTM32F103C.menu.upload_method.BMPMethod.build.upload_flags=-DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG
213213

214+
215+
genericSTM32F103C.menu.upload_method.jlinkMethod=JLink
216+
genericSTM32F103C.menu.upload_method.jlinkMethod.upload.protocol=jlink
217+
genericSTM32F103C.menu.upload_method.jlinkMethod.upload.tool=jlink_upload
218+
genericSTM32F103C.menu.upload_method.jlinkMethod.build.upload_flags=-DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG=1 -DSERIAL_USB -DGENERIC_BOOTLOADER
219+
214220
########################### Generic STM32F103R ###########################
215221

216222
genericSTM32F103R.name=Generic STM32F103R series
@@ -519,4 +525,4 @@ genericGD32F103C.menu.cpu_speed.speed_96mhz=96Mhz (Stable)
519525
genericGD32F103C.menu.cpu_speed.speed_96mhz.build.f_cpu=96000000L
520526

521527
genericGD32F103C.menu.cpu_speed.speed_72mhz=72Mhz (compatibility)
522-
genericGD32F103C.menu.cpu_speed.speed_72mhz.build.f_cpu=72000000L
528+
genericGD32F103C.menu.cpu_speed.speed_72mhz.build.f_cpu=72000000L

STM32F1/cores/maple/HardwareTimer.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,28 @@ void HardwareTimer::refresh(void) {
142142
timer_generate_update(this->dev);
143143
}
144144

145+
/* CARLOS Changes to add encoder mode.*/
146+
147+
//direction of movement. (to be better described).
148+
uint8 HardwareTimer::getDirection(){
149+
return get_direction(this->dev);
150+
}
151+
152+
//set if the encoder will count edges on one, which or both channels.
153+
void HardwareTimer::setEdgeCounting(uint32 counting) {
154+
(dev->regs).gen->SMCR = counting;//TIMER_SMCR_SMS_ENCODER3; //choose encoder 3, counting on
155+
156+
}
157+
158+
uint8 HardwareTimer::getEdgeCounting() {
159+
return (dev->regs).gen->SMCR;
160+
}
161+
162+
163+
164+
//set the polarity of counting... not sure how interesting this is..
165+
void HardwareTimer::setPolarity(){}
166+
145167
/* -- Deprecated predefined instances -------------------------------------- */
146168

147169
HardwareTimer Timer1(1);

STM32F1/cores/maple/HardwareTimer.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
/** Timer mode. */
3939
typedef timer_mode TimerMode;
4040

41+
//CARLOS
42+
//defines for the ENCODER mode.
43+
44+
4145
/**
4246
* @brief Interface to one of the 16-bit timer peripherals.
4347
*/
@@ -205,6 +209,23 @@ class HardwareTimer {
205209
*/
206210
void refresh(void);
207211

212+
//CARLOS.
213+
/*
214+
added these functions to make sense for the encoder mode.
215+
*/
216+
//direction of movement. (to be better described).
217+
uint8 getDirection();
218+
219+
//set if the encoder will count edges on one, which or both channels.
220+
void setEdgeCounting(uint32 counting);
221+
uint8 getEdgeCounting(); //not sure if needed.
222+
223+
//set the polarity of counting... not sure how interesting this is..
224+
void setPolarity();
225+
226+
//add the filtering definition for the input channel.
227+
228+
208229
/* Escape hatch */
209230

210231
/**

STM32F1/cores/maple/libmaple/adc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
*
4545
* @param dev ADC peripheral to initialize
4646
*/
47-
void adc_init(const adc_dev *dev) {
47+
void adc_init(adc_dev *dev) {
4848
rcc_clk_enable(dev->clk_id);
4949
rcc_reset_dev(dev->clk_id);
5050
}
@@ -55,7 +55,7 @@ void adc_init(const adc_dev *dev) {
5555
* @param event Event used to trigger the start of conversion.
5656
* @see adc_extsel_event
5757
*/
58-
void adc_set_extsel(const adc_dev *dev, adc_extsel_event event) {
58+
void adc_set_extsel(adc_dev *dev, adc_extsel_event event) {
5959
uint32 cr2 = dev->regs->CR2;
6060
cr2 &= ~ADC_CR2_EXTSEL;
6161
cr2 |= event;
@@ -71,7 +71,7 @@ void adc_set_extsel(const adc_dev *dev, adc_extsel_event event) {
7171
* @param smp_rate sample rate to set
7272
* @see adc_smp_rate
7373
*/
74-
void adc_set_sample_rate(const adc_dev *dev, adc_smp_rate smp_rate) {
74+
void adc_set_sample_rate(adc_dev *dev, adc_smp_rate smp_rate) {
7575
uint32 adc_smpr1_val = 0, adc_smpr2_val = 0;
7676
int i;
7777

@@ -95,7 +95,7 @@ void adc_set_sample_rate(const adc_dev *dev, adc_smp_rate smp_rate) {
9595
* @param channel channel to convert
9696
* @return conversion result
9797
*/
98-
uint16 adc_read(const adc_dev *dev, uint8 channel) {
98+
uint16 adc_read(adc_dev *dev, uint8 channel) {
9999
adc_reg_map *regs = dev->regs;
100100

101101
adc_set_reg_seqlen(dev, 1);

STM32F1/cores/maple/libmaple/adc_f1.c

Lines changed: 108 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
#include <libmaple/adc.h>
3636
#include <libmaple/gpio.h>
37+
#include <libmaple/nvic.h>//Added by bubulindo.
3738

3839
/*
3940
* Devices
@@ -42,26 +43,126 @@
4243
adc_dev adc1 = {
4344
.regs = ADC1_BASE,
4445
.clk_id = RCC_ADC1,
46+
.handlers = {[3]=0}, //added by bubulindo. EOC, JEOC, AWD
47+
.irq_num = NVIC_ADC_1_2,
4548
};
4649
/** ADC1 device. */
47-
const adc_dev *ADC1 = &adc1;
50+
adc_dev *ADC1 = &adc1;
4851

4952
adc_dev adc2 = {
5053
.regs = ADC2_BASE,
5154
.clk_id = RCC_ADC2,
5255
};
5356
/** ADC2 device. */
54-
const adc_dev *ADC2 = &adc2;
57+
adc_dev *ADC2 = &adc2;
5558

5659
#if defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY)
5760
adc_dev adc3 = {
5861
.regs = ADC3_BASE,
5962
.clk_id = RCC_ADC3,
63+
.handlers = {[3]=0}, //added by bubulindo. EOC, JEOC, AWD
64+
.irq_num = NVIC_ADC3,//added by bubulindo.
6065
};
6166
/** ADC3 device. */
62-
const adc_dev *ADC3 = &adc3;
67+
adc_dev *ADC3 = &adc3;
6368
#endif
6469

70+
71+
/*
72+
adc irq routine.
73+
Added by bubulindo.
74+
*/
75+
void __irq_adc() {
76+
//get status
77+
uint32 adc_sr = ADC1->regs->SR;
78+
//End Of Conversion
79+
if (adc_sr & (1U << ADC_SR_EOC_BIT)) {
80+
ADC1->regs->SR &= ~(1<<ADC_SR_EOC_BIT);
81+
void (*handler)(void) = ADC1->handlers[ADC_EOC];
82+
if (handler) {
83+
handler();
84+
}
85+
}
86+
//Injected End Of Conversion
87+
if (adc_sr & (1U << ADC_SR_JEOC_BIT)) {
88+
ADC1->regs->SR &= ~(1<<ADC_SR_JEOC_BIT);
89+
void (*handler)(void) = ADC1->handlers[ADC_JEOC];
90+
if (handler) {
91+
handler();
92+
}
93+
}
94+
//Analog Watchdog
95+
if (adc_sr & (1U << ADC_SR_AWD_BIT)) {
96+
ADC1->regs->SR &= ~(1<<ADC_SR_AWD_BIT);
97+
void (*handler)(void) = ADC1->handlers[ADC_AWD];
98+
if (handler) {
99+
handler();
100+
}
101+
}
102+
};//end of adc irq
103+
104+
105+
/*
106+
ADC3 IRQ handler.
107+
added by bubulindo
108+
*/
109+
#if defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY)
110+
void __irq_adc3() {
111+
//get status
112+
uint32 adc_sr = ADC3->regs->SR;
113+
//End Of Conversion
114+
if (adc_sr & (1U << ADC_SR_EOC_BIT)) {
115+
ADC3->regs->SR &= ~(1<<ADC_SR_EOC_BIT);
116+
void (*handler)(void) = ADC3->handlers[ADC_EOC];
117+
if (handler) {
118+
handler();
119+
}
120+
}
121+
//Injected End Of Conversion
122+
if (adc_sr & (1U << ADC_SR_JEOC_BIT)) {
123+
ADC3->regs->SR &= ~(1<<ADC_SR_JEOC_BIT);
124+
void (*handler)(void) = ADC3->handlers[ADC_JEOC];
125+
if (handler) {
126+
handler();
127+
}
128+
}
129+
//Analog Watchdog
130+
if (adc_sr & (1U << ADC_SR_AWD_BIT)) {
131+
ADC3->regs->SR &= ~(1<<ADC_SR_AWD_BIT);
132+
void (*handler)(void) = ADC3->handlers[ADC_AWD];
133+
if (handler) {
134+
handler();
135+
}
136+
}
137+
};//end of ADC3 irq
138+
#endif
139+
140+
/*
141+
enable interrupts on the ADC:
142+
use ADC_EOC, ADC_JEOC, ADC_AWD
143+
This will set up the interrupt bit in the ADC as well as in the NVIC.
144+
added by bubulindo
145+
*/
146+
void adc_enable_irq(adc_dev* dev, uint8 interrupt) {//ADC1 for now.
147+
dev->regs->CR1 |= (1U<<(interrupt +ADC_CR1_EOCIE_BIT));
148+
nvic_irq_enable(dev->irq_num);
149+
}
150+
151+
/*
152+
attach interrupt functionality for ADC
153+
use ADC_EOC, ADC_JEOC, ADC_AWD
154+
added by bubulindo
155+
*/
156+
157+
void adc_attach_interrupt(adc_dev *dev,
158+
uint8 interrupt,
159+
voidFuncPtr handler) {
160+
dev->handlers[interrupt] = handler;
161+
adc_enable_irq(dev, interrupt);
162+
//enable_irq(dev, interrupt); //I need to create this function. to enable NVIC
163+
// nvic_irq_enable()
164+
}
165+
65166
/*
66167
* STM32F1 routines
67168
*/
@@ -73,7 +174,7 @@ const adc_dev *ADC3 = &adc3;
73174
*
74175
* @param dev adc device
75176
*/
76-
void adc_calibrate(const adc_dev *dev) {
177+
void adc_calibrate(adc_dev *dev) {
77178
__io uint32 *rstcal_bit = bb_perip(&(dev->regs->CR2), 3);
78179
__io uint32 *cal_bit = bb_perip(&(dev->regs->CR2), 2);
79180

@@ -94,19 +195,19 @@ void adc_set_prescaler(adc_prescaler pre) {
94195
rcc_set_prescaler(RCC_PRESCALER_ADC, (uint32)pre);
95196
}
96197

97-
void adc_foreach(void (*fn)(const adc_dev*)) {
198+
void adc_foreach(void (*fn)(adc_dev*)) {
98199
fn(ADC1);
99200
fn(ADC2);
100201
#if defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY)
101202
fn(ADC3);
102203
#endif
103204
}
104205

105-
void adc_config_gpio(const adc_dev *ignored, gpio_dev *gdev, uint8 bit) {
206+
void adc_config_gpio(adc_dev *ignored, gpio_dev *gdev, uint8 bit) {
106207
gpio_set_mode(gdev, bit, GPIO_INPUT_ANALOG);
107208
}
108209

109-
void adc_enable_single_swstart(const adc_dev *dev) {
210+
void adc_enable_single_swstart(adc_dev *dev) {
110211
adc_init(dev);
111212
adc_set_extsel(dev, ADC_SWSTART);
112213
adc_set_exttrig(dev, 1);

STM32F1/cores/maple/libmaple/timer.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
static void disable_channel(timer_dev *dev, uint8 channel);
3939
static void pwm_mode(timer_dev *dev, uint8 channel);
4040
static void output_compare_mode(timer_dev *dev, uint8 channel);
41+
static void encoder_mode(timer_dev *dev, uint8 channel) ;//CARLOS
42+
4143

4244
static inline void enable_irq(timer_dev *dev, timer_interrupt_id iid);
4345

@@ -230,6 +232,10 @@ void timer_set_mode(timer_dev *dev, uint8 channel, timer_mode mode) {
230232
case TIMER_OUTPUT_COMPARE:
231233
output_compare_mode(dev, channel);
232234
break;
235+
//added by CARLOS.
236+
case TIMER_ENCODER:
237+
encoder_mode(dev, channel); //find a way to pass all the needed stuff on the 8bit var
238+
break;
233239
}
234240
}
235241

@@ -293,6 +299,13 @@ void timer_detach_interrupt(timer_dev *dev, uint8 interrupt) {
293299
dev->handlers[interrupt] = NULL;
294300
}
295301

302+
//CARLOS
303+
uint8 get_direction(timer_dev *dev){
304+
return *bb_perip(&(dev->regs).gen->CR1, TIMER_CR1_DIR_BIT);
305+
}
306+
307+
308+
296309
/*
297310
* Utilities
298311
*/
@@ -313,6 +326,31 @@ static void output_compare_mode(timer_dev *dev, uint8 channel) {
313326
timer_cc_enable(dev, channel);
314327
}
315328

329+
//added by CARLOS.
330+
static void encoder_mode(timer_dev *dev, uint8 channel) {
331+
332+
//prescaler.
333+
//(dev->regs).gen->PSC = 1;
334+
335+
//map inputs.
336+
(dev->regs).gen->CCMR1 = TIMER_CCMR1_CC1S_INPUT_TI1 | TIMER_CCMR1_CC2S_INPUT_TI2 | TIMER_CCMR1_IC2F | TIMER_CCMR1_IC1F ;
337+
338+
(dev->regs).gen->SMCR = TIMER_SMCR_SMS_ENCODER3; //choose encoder 3, counting on both edges.
339+
340+
//polarity
341+
//(dev->regs).gen->CCER = TIMER_CCER_CC1P; //to invert the counting, only one of the inputs should be inverted.
342+
343+
//set the interval used by the encoder.
344+
//timer_set_reload(dev, 1000);
345+
346+
// (dev->regs).gen->CR1 |=TIMER_CR1_UDIS_BIT;
347+
348+
//run timer
349+
timer_resume(dev);
350+
}
351+
352+
353+
316354
static void enable_adv_irq(timer_dev *dev, timer_interrupt_id id);
317355
static void enable_bas_gen_irq(timer_dev *dev);
318356

STM32F1/cores/maple/libmaple/usb/usb_lib/usb_core.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@
3131
#define USB_StatusIn() Send0LengthData()
3232
#define USB_StatusOut() vSetEPRxStatus(EP_RX_VALID)
3333

34-
#define StatusInfo0 StatusInfo.bw.bb1 /* Reverse bb0 & bb1 */
35-
#define StatusInfo1 StatusInfo.bw.bb0
36-
3734
/* Private macro -------------------------------------------------------------*/
3835
/* Private variables ---------------------------------------------------------*/
3936
u16_u8 StatusInfo;
@@ -857,11 +854,11 @@ u8 Setup0_Process(void)
857854
pInformation->USBbmRequestType = *pBuf.b++; /* bmRequestType */
858855
pInformation->USBbRequest = *pBuf.b++; /* bRequest */
859856
pBuf.w++; /* word not accessed because of 32 bits addressing */
860-
pInformation->USBwValue = ByteSwap(*pBuf.w++); /* wValue */
857+
pInformation->USBwValue = *pBuf.w++; /* wValue in Little Endian */
861858
pBuf.w++; /* word not accessed because of 32 bits addressing */
862-
pInformation->USBwIndex = ByteSwap(*pBuf.w++); /* wIndex */
859+
pInformation->USBwIndex = *pBuf.w++; /* wIndex in Little Endian */
863860
pBuf.w++; /* word not accessed because of 32 bits addressing */
864-
pInformation->USBwLength = *pBuf.w; /* wLength */
861+
pInformation->USBwLength = *pBuf.w; /* wLength in Little Endian */
865862
}
866863

867864
pInformation->ControlState = SETTING_UP;

STM32F1/cores/maple/wirish_analog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
* to INPUT_ANALOG. That's faster, but it does require some extra work
3939
* on the user's part. Not too much, we think ;). */
4040
uint16 analogRead(uint8 pin) {
41-
const adc_dev *dev = PIN_MAP[pin].adc_device;
41+
adc_dev *dev = PIN_MAP[pin].adc_device;
4242
if (dev == NULL) {
4343
return 0;
4444
}

STM32F1/cores/maple/wirish_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
typedef struct stm32_pin_info {
5252
gpio_dev *gpio_device; /**< Maple pin's GPIO device */
5353
timer_dev *timer_device; /**< Pin's timer device, if any. */
54-
const adc_dev *adc_device; /**< ADC device, if any. */
54+
adc_dev *adc_device; /**< ADC device, if any. */
5555
uint8 gpio_bit; /**< Pin's GPIO port bit. */
5656
uint8 timer_channel; /**< Timer channel, or 0 if none. */
5757
uint8 adc_channel; /**< Pin ADC channel, or ADCx if none. */

0 commit comments

Comments
 (0)