Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
%DASHBOARD{ section="banner" | ||||||||
Line: 7 to 7 | ||||||||
titlestyle="color:#F00000;"
}%
Intro
| ||||||||
Changed: | ||||||||
< < | The board support package for the STM32WB Firefly Development Board is restricted to the Arduino UNO R3 pin header and the onboard LED and switch (button). The STM32 has much more capabilities then 14 digital I/O pins, 5 analog input pins, UART, SPI, and I2C interfaces. But if you want to use the more advanced features you can use the CubeMX to create source code for the internal peripherals. This project wants to show how to use the Cube Ecosystem for a Forth system (or vice versa) and can't implement all features and possibilities the STM32WB has. It is a good starting point for your project. | |||||||
> > | The board support package for the STM32WB Firefly Development Board is restricted to the Arduino UNO R3 pin header and the onboard LED and switch (button). The STM32 has much more capabilities then 16 digital I/O pins, 5 analog input pins, UART, SPI, and I2C interfaces. But if you want to use the more advanced features you can use the CubeMX to create source code for the internal peripherals. This project wants to show how to use the Cube Ecosystem for a Forth system (or vice versa) and can't implement all features and possibilities the STM32WB has. It is a good starting point for your project. | |||||||
Line: 24 to 24 | ||||||||
dport! ( n -- ) sets the digital output port (D0=bit0 .. D15=bit15). dport@ ( -- n ) gets the digital input/output port (D0=bit0 .. D15=bit15). | ||||||||
Changed: | ||||||||
< < | dpin! ( n a -- ) sets the digital output port pin (D0=0 .. D15=15) | |||||||
> > | dpin! ( n a -- ) sets the digital output port pin (D0=0 .. D15=15, A0=16 .. A4=20) | |||||||
dpin@ ( a -- n ) gets the digital input/output port pin dmod ( u a -- ) sets the pin mode: 0 in, 1 in pull-up, 2 in pull-down, 3 out push pull, 4 out open drain, 5 out push pull PWM, 6 input capture, 7 output compare, 8 I2C | ||||||||
Line: 32 to 32 | ||||||||
EXTImod ( u a -- ) Sets for pin a (D2, D4, D7, D10) the EXTI mode u: 0 rising, 1 falling, 2 both edges, 3 none EXTIwait ( u a -- ) Wait for EXTI interrupt on pin a (D2, D4, D7, D10), timeout u in [ms] | ||||||||
Changed: | ||||||||
< < | pwmpin! ( u a -- ) sets the digital output port pin a (D3=3, D6=6, D9=9) to a PWM value u (0..1000). Default frequency is 1 kHz, TIMER1 | |||||||
> > | pwmpin! ( u a -- ) sets the digital output port pin a (D0=0, D1=1, A4=20) to a PWM value u (0..1000). Default frequency is 1 kHz, TIMER1 | |||||||
pwmprescale ( u -- ) Sets the PWM prescale for TIMER1. 32 kHz / prescale, default 32 -> PWM frequency 1 kHz ICOCprescale ( u -- ) Sets the input capture / output compare prescale for TIMER2. default 32 -> 32 MHz / 32 = 1 MHz, timer resolution 1 us | ||||||||
Line: 43 to 43 | ||||||||
ICOCcount@ ( u -- ) Gets the input capture / output compare counter for TIMER2 ICOCstart ( -- ) Starts the ICOC period ICOCstop ( -- ) Stops the ICOC period | ||||||||
Changed: | ||||||||
< < | OCmod ( u a -- ) Sets for pin a (D0, D1, D5) the Output Compare mode u: 0 frozen, 1 active level on match, 2 inactive level on match, | |||||||
> > | OCmod ( u a -- ) Sets for pin a (D13=13, A2=18, A3=19) the Output Compare mode u: 0 frozen, 1 active level on match, 2 inactive level on match, | |||||||
3 toggle on match, 4 forced active, 5 forced inactive OCstart ( u a -- ) Starts the output compare mode for pin a with pulse u | ||||||||
Line: 55 to 55 | ||||||||
OCwait ( a -- ) wait for the end of output capture on pin a ICwait ( u -- u ) wait for the end of input capture with timeout u, returns counter u | ||||||||
Changed: | ||||||||
< < | apin@ ( a -- u ) gets the analog input port pin (A0 .. A5). Returns a 12 bit value (0..4095) | |||||||
> > | apin@ ( a -- u ) gets the analog input port pin (A0 .. A4). Returns a 12 bit value (0..4095) | |||||||
I2Cdev ( u -- ) Sets the 7-bit I2C address I2Cput ( c-addr u -- ) put a message with length u from buffer at c-addr to the I2C slave device | ||||||||
Line: 73 to 73 | ||||||||
Changed: | ||||||||
< < | This example is very similar to the McForth#Knight_Rider program. dport! and dport@ set and get all 16 digital pins (D0 to D15) at once. You have to press the SW1 push button til D0 is set to cancel the operation. | |||||||
> > | This example is very similar to the McForth#Knight_Rider program. dport! and dport@ set and get all 16 digital pins (D0 to D15) at once. You have to press the SW1 push button til D0 is set to cancel the operation. Be aware the D0 and D1 pins are shared with the UART. | |||||||
3 0 dmod \ set D0 to Output 3 1 dmod \ set D1 to Output | ||||||||
Line: 167 to 167 | ||||||||
Changed: | ||||||||
< < | apin@ ( a -- u ) returns the ADC value (12 bit, 0 .. 4095) from one of the analog pins A0 to A5 (0 .. 5). Here I use the A0 to control the delay. | |||||||
> > | apin@ ( a -- u ) returns the ADC value (12 bit, 0 .. 4095) from one of the analog pins A0 to A4 (0 .. 4). Here I use the A0 to control the delay. | |||||||
| ||||||||
Line: 208 to 208 | ||||||||
Using the PWM (Analog Output Pins)Only three port pins are supported so far. The 16 bit TIMER1 is used for the timebase, time resolution is 1 us (32 MHz SysClk divided by 32). The PWM scale is from 0 (0 % duty cycle) to 1000 (100 % duty cycle), this results in a PWM frequency of 1 kHz. If you need higher PWM frequencies, decrease the divider and/or the scale. | ||||||||
Changed: | ||||||||
< < | PWM port pins: D6 (TIM1CH1), D9 (TIM1CH2), D3 (TIM1CH3) | |||||||
> > | PWM port pins: D0 (TIM1CH3), D1 (TIM1CH2), A4 (TIM1CH1) | |||||||
Changed: | ||||||||
< < | Simple test program to set brightness of a LED on pin D3 with a potentiometer on A0. Default PWM frequency is 1 kHz (prescaler set to 32). You can set the prescale with the word pwmprescale from 32 kHz (value 1) down to 0.5 Hz (64000). | |||||||
> > | Simple test program to set brightness of a LED on pin A4 with a potentiometer on A0. Default PWM frequency is 1 kHz (prescaler set to 32). You can set the prescale with the word pwmprescale from 32 kHz (value 1) down to 0.5 Hz (64000). | |||||||
Changed: | ||||||||
< < | 5 3 dmod \ set D3 to PWM | |||||||
> > | 5 20 dmod \ set A4 to PWM | |||||||
: pwm ( -- ) begin | ||||||||
Changed: | ||||||||
< < | 0 apin@ 4 / 3 pwmpin! | |||||||
> > | 0 apin@ 4 / 20 pwmpin! | |||||||
10 osDelay drop switch1? until | ||||||||
Line: 247 to 247 | ||||||||
Output Compare | ||||||||
Added: | ||||||||
> > | Output compare port pins: D13=13 (TIM2CH1), A2=18 (TIM2CH3), A3=19 (TIM1CH4) | |||||||
: oc-toggle ( -- ) 5000000 ICOCperiod! \ 5 s period ICOCstart | ||||||||
Changed: | ||||||||
< < | 3 0 OCmod 1000000 0 OCstart \ toggle D0 after 1 s 3 1 OCmod 2000000 1 OCstart \ toggle D1 after 2 s 3 5 OCmod 3000000 5 OCstart \ toggle D5 after 3 s | |||||||
> > | 3 13 OCmod 1000000 13 OCstart \ toggle D13 after 1 s 3 18 OCmod 2000000 18 OCstart \ toggle A2 after 2 s 3 19 OCmod 3000000 19 OCstart \ toggle A3 after 3 s | |||||||
begin waitperiod cr .time | ||||||||
Line: 264 to 266 | ||||||||
When you abort (hit any key) the program, the timer still runs and controls the port pins. To stop the port pins:
| ||||||||
Changed: | ||||||||
< < | 0 OCstop 1 OCstop 5 OCstop | |||||||
> > | 13 OCstop 18 OCstop 19 OCstop | |||||||
Or change the prescale to make it faster or slower: | ||||||||
Line: 275 to 277 | ||||||||
Input Capture | ||||||||
Changed: | ||||||||
< < | This sample program measures the time between the edges on port A2. if no event occurs within 2 seconds, "timeout" is issued. Hit any key to abort program. | |||||||
> > | Input capture port pin: A1 (TIM2CH2) This sample program measures the time between the edges on port A1. if no event occurs within 2 seconds, "timeout" is issued. Hit any key to abort program. | |||||||
: ic-test ( -- ) | ||||||||
Changed: | ||||||||
< < | 6 2 dmod \ input capture on A2 | |||||||
> > | 6 17 dmod \ input capture on A1 | |||||||
ICOCstart 2 ICstart \ both edges ICOCcount@ ( -- count ) | ||||||||
Line: 305 to 309 | ||||||||
Added: | ||||||||
> > | EXTI port pins: D2 (PB5), D3 (PB4), D5 (PB3), D6 (PB2), D7 (PB1) | |||||||
: exti-test ( -- ) 2 2 EXTImod \ both edges on D2 |