Added defined for __STM32F1XX__ to board.txt in preparation for changes to OneWire library. Also added analogWrite function to replicate what the Arduino API does, and fix the issue with needing to call pinMode with type PWM. Fade example now works, as long as a PWM compatible pin is used e.g. PA0

This commit is contained in:
Roger Clark 2014-12-03 21:32:00 +11:00
parent a83c251cea
commit 794a79a151
4 changed files with 31 additions and 14 deletions

View File

@ -17,7 +17,7 @@ maple.upload.auto_reset=true
maple.build.mcu=cortex-m3
maple.build.f_cpu=72000000L
maple.build.core=maple
maple.build.extra_flags=-DMCU_STM32F103RB -mthumb -DSTM32_MEDIUM_DENSITY -DBOOTLOADER_maple -march=armv7-m
maple.build.extra_flags=-DMCU_STM32F103RB -mthumb -DSTM32_MEDIUM_DENSITY -DBOOTLOADER_maple -march=armv7-m -D__STM32F1XX__
maple.build.ldscript=ld/flash.ld
maple.build.variant=maple
maple.build.variant_system_lib=libmaple.a
@ -43,7 +43,7 @@ mapleRAM.upload.auto_reset=true
mapleRAM.build.mcu=cortex-m3
mapleRAM.build.f_cpu=72000000L
mapleRAM.build.core=maple
mapleRAM.build.extra_flags=-DMCU_STM32F103RB -mthumb -MD -DSTM32_MEDIUM_DENSITY -DBOOTLOADER_maple -march=armv7-m
mapleRAM.build.extra_flags=-DMCU_STM32F103RB -mthumb -MD -DSTM32_MEDIUM_DENSITY -DBOOTLOADER_maple -march=armv7-m -D__STM32F1XX__
mapleRAM.build.ldscript=ld/ram.ld
mapleRAM.build.variant=maple
mapleRAM.build.variant_system_lib=libmaple.a
@ -70,7 +70,7 @@ maple_mini.upload.auto_reset=true
maple_mini.build.mcu=cortex-m3
maple_mini.build.f_cpu=72000000L
maple_mini.build.core=maple
maple_mini.build.extra_flags=-DMCU_STM32F103CB -mthumb -MD -DSTM32_MEDIUM_DENSITY -DBOOTLOADER_maple -march=armv7-m
maple_mini.build.extra_flags=-DMCU_STM32F103CB -mthumb -MD -DSTM32_MEDIUM_DENSITY -DBOOTLOADER_maple -march=armv7-m -D__STM32F1XX__
maple_mini.build.ldscript=ld/flash.ld
maple_mini.build.variant=maple_mini
maple_mini.build.variant_system_lib=libmaple.a
@ -96,7 +96,7 @@ mapleRAM.upload.auto_reset=true
maple_miniRAM.build.mcu=cortex-m3
maple_miniRAM.build.f_cpu=72000000L
maple_miniRAM.build.core=maple
mapleRAM.build.extra_flags=-DMCU_STM32F103CB -mthumb -MD -DSTM32_MEDIUM_DENSITY -DBOOTLOADER_maple -march=armv7-m
mapleRAM.build.extra_flags=-DMCU_STM32F103CB -mthumb -MD -DSTM32_MEDIUM_DENSITY -DBOOTLOADER_maple -march=armv7-m -D__STM32F1XX__
mapleRAM.build.ldscript=ld/ram.ld
mapleRAM.build.variant=maple_mini
mapleRAM.build.variant_system_lib=libmaple.a
@ -123,7 +123,7 @@ maple_STM32.upload.auto_reset=true
maple_STM32.build.mcu=cortex-m3
maple_STM32.build.f_cpu=72000000L
maple_STM32.build.core=maple
maple_STM32.build.extra_flags=-DMCU_STM32F103CB -mthumb -MD -DSTM32_MEDIUM_DENSITY -march=armv7-m
maple_STM32.build.extra_flags=-DMCU_STM32F103CB -mthumb -MD -DSTM32_MEDIUM_DENSITY -march=armv7-m -D__STM32F1XX__
maple_STM32.build.ldscript=ld/jtag.ld
maple_STM32.build.variant=maple_mini
maple_STM32.build.variant_system_lib=libmaple.a

View File

@ -36,6 +36,7 @@
#include <libmaple/timer.h>
#include "boards.h"
#include "io.h"
void pwmWrite(uint8 pin, uint16 duty_cycle) {
if (pin >= BOARD_NR_GPIO_PINS) {
@ -46,3 +47,15 @@ void pwmWrite(uint8 pin, uint16 duty_cycle) {
ASSERT(dev && cc_channel);
timer_set_compare(dev, cc_channel, duty_cycle);
}
/*
* Roger Clark. Added new function to replicate more closely what the Arduino API does
* Note. This implementation is currently slower than it could be,
* because pinMode needs to be called to set the special (new) mode of PWM
* Some optimisation may be possible with pinMode or even in this function
*/
void analogWrite(uint8 pin, int duty_cycle8)
{
pinMode(pin,PWM);
pwmWrite(pin,duty_cycle8 * 257);// 257 maps 255 to 65535 (i.e 255*257 = 65535)
}

View File

@ -34,13 +34,6 @@
#include <libmaple/libmaple_types.h>
/**
* As a convenience, analogWrite is an alias of pwmWrite to ease
* porting Arduino code. However, period and duty will have to be
* recalibrated.
*/
#define analogWrite pwmWrite
/**
* Set the PWM duty on the given pin.
*
@ -48,9 +41,19 @@
* (based on the configured period).
*
* @param pin PWM output pin
* @param duty_cycle Duty cycle to set.
* @param duty_cycle Duty cycle to set. (Range is 0 to 65535)
*/
void pwmWrite(uint8 pin, uint16 duty_cycle);
void pwmWrite(uint8 pin, uint16 duty_cycle16);
/**
* Roger Clark. 20140103
* Added function to replicate the Arduino PWM functionality or range 0 to 255
* User code is expected to determine and honor the maximum value
* (based on the configured period).
*
* @param pin PWM output pin
* @param duty_cycle Duty cycle to set. (Range is 0 to 255)
*/
void analogWrite(uint8 pin, int duty_cycle8);
#endif

View File

@ -55,6 +55,7 @@ typedef struct stm32_pin_info {
uint8 gpio_bit; /**< Pin's GPIO port bit. */
uint8 timer_channel; /**< Timer channel, or 0 if none. */
uint8 adc_channel; /**< Pin ADC channel, or ADCx if none. */
uint8 pinMode; /**< mode specific by pinMode call (Roger Clark added to optimize compatibility with Arduino API*/
} stm32_pin_info;
/**