%DASHBOARD{ section="dashboard_start" }% %DASHBOARD{ section="banner" image="%PUBURLPATH%/MecrispCube/BoardSupportPackageWBfeather/WB_Feather_header.jpg" title="Board Support Package for the !STM32WB Feather Development Board" titlestyle="color:#F00000;" }% %DASHBOARD{ section="box_start" title="Intro" width="485" height="250"}% The board support package for the !STM32WB Feather Development Board (see https://www.reclaimerlabs.com/stm32wb-feather) is restricted to the JP1 and JP3 pin header, the onboard LEDs and switches (buttons), and the onboard 16 !MiB [[https://www.mouser.ch/datasheet/2/949/w25q128jv_revf_03272018_plus-1489608.pdf][serial NOR flash]]. The !STM32WB55 has much more capabilities than 11 digital I/O pins, 6 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. [[MecrispCubeWBfeather][Mecrisp-Cube for the STM32WB55 Feather Development Board]] %DASHBOARD{ section="box_end" }% %DASHBOARD{ section="box_start" title="Contents" width="460" height="250"}% %TOC% %DASHBOARD{ section="box_end" }% %DASHBOARD{ section="box_start" width="992" height="600" }% ---+ Overview %IMAGE{"%PUBURLPATH%/MecrispCube/BoardSupportPackageWBfeather/WB_Feather_oled_sdcard.jpg" type="thumb" caption="WB Feather together with OLED and E-Ink Wing. The I-Ink Wing is used only for uSD slot."}% * [[MicroSdBlocks][microSD and internal Flash mass storage]] for blocks and FAT filesystem. * Internal Flash drive 16 !MiB (SPI) * [[MicroSdBlocks#Filesystem_API][Filesystem API]] (SPI) * [[MicroSdBlocks#UNIX_like_Shell_Commands][UNIX like Shell commands]] * Digital and analog pins * LEDs: LED1 (red) D12 * Digital port pins: D0 to D15 (without D7 and D8) * Analog port pins: A0 to A5 * PWM: !TIM1CH1 A4, !TIM1CH2 D1, !TIM1CH3 D0 * Input capture !TIM2CH1 A5 * Output compare !TIM2CH2 D13, !TIM2CH3 D5, !TIM2CH4 D6 * EXTI: D5, D6, D11, D13 * UART: D0 RX, D1 TX * SPI: D2 SCK, D3 MISO, D4 MOSI (e.g. for display, memory) * !I2C: D14 SDA, D15 SCL (external peripherals e.g. pressure) * NeoPixel shares the LED D12 pin. It is easy to add an Adafruit [[https://www.adafruit.com/product/1312][pixel breakout board]] or a [[https://www.adafruit.com/product/1260][Flora Pixel]] at the top of the shield. The LED can be used concurrently. * green: successfull USB enumeration * blue: BLE connected * flashing red: file write operation * flashing yellow: file read operation * [[OledDisplay][OLED]] Feather Wing * Switches: SW1 (button A, D9), SW2 (button B, D6), SW3 (button C, D5) * !I2C: D14 SDA, D15 SCL * CharlieWing * NeoPixelWing * DotStarWing Defaults for digital port pins: * D1 (UART_TX), D2 (SPI SCK), D4 (SPI MOSI), D10 (SD CS), and D12 (LED) are outputs * D3 (SPI MISO) and D11 to D13 are inputs * D0 (UART_RX), D5 (button), D6 (button), D9 (button) are inputs with internal pull-up resistors * D14 (SDA) and D15 (SCL) are open drain outputs with 4.7 kOhm pull-up resistors %DASHBOARD{ section="box_end" }% %DASHBOARD{ section="box_start" width="992" height="600" }% ---+ Board Support Words <pre> led1! ( n -- ) sets LED1 (red) led1@ ( -- n ) gets LED1 (red) neopixel! ( rgb -- ) sets the neopixel RGB led ($ff0000 red, $00ff00 green, $0000ff blue) neopixel@ ( -- rgb ) gets the neopixel RGB led ($ff0000 red, $00ff00 green, $0000ff blue) switch1? ( -- flag ) gets switch1 (button A), closed=TRUE switch2? ( -- flag ) gets switch2 (button B), closed=TRUE switch3? ( -- flag ) gets switch3 (button C), closed=TRUE switchuser? ( -- flag ) gets user button, closed=TRUE dport! ( n -- ) sets the digital output port (D0=bit0 .. D15=bit15). dport@ ( -- n ) gets the digital input/output port (D0=bit0 .. D15=bit15). dpin! ( n a -- ) sets the digital output port pin a (D0=0 .. D15=15, A0=16 .. A6=22) dpin@ ( a -- n ) gets the digital input/output port pin a 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, 9 USART, 10 analog EXTImod ( u a -- ) Sets for pin a (D5, D6, D11, D13) the EXTI mode u: 0 rising, 1 falling, 2 both edges, 3 none EXTIwait ( u a -- ) Wait for EXTI interrupt on pin a (D5, D6, D11, D13), timeout u in [ms] 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 ICOCperiod! ( u -- ) Sets the input capture / output compare (TIMER2) period. default $FFFFFFFF (4'294'967'295). When the up counter reaches the period, the counter is set to 0. For prescale 32 the maximum time is about 1 h 11 m ICOCcount! ( -- u ) Sets the input capture / output compare counter for TIMER2 ICOCcount@ ( u -- ) Gets the input capture / output compare counter for TIMER2 ICOCstart ( -- ) Starts the ICOC period ICOCstop ( -- ) Stops the ICOC period OCmod ( u a -- ) Sets for pin a (D5, D6, D13) 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 OCstop ( a -- ) Stops output compare for pin a ICstart ( u -- ) Starts input capture u for pin A5: 0 rising edge, 1 falling edge, 2 both edges ICstop ( -- ) Stops input capture waitperiod ( -- ) wait for the end of the TIMER2 period 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 apin@ ( a -- u ) gets the analog input port pin (A0=0 .. A5=5). Returns a 12 bit value (0..4095) </pre> %DASHBOARD{ section="box_end" }% %DASHBOARD{ section="box_start" width="992" height="520" }% ---+ Using the Digital Port Pins (Input and Output) Set 8 port pins to push/pull output <pre> 3 15 dmod \ set D15 (SCL) to Output 3 5 dmod \ set D5 to Output 3 6 dmod \ set D6 to Output 3 9 dmod \ set D9 to Output 3 10 dmod \ set D10 to Output 3 11 dmod \ set D11 to output 3 12 dmod \ set D12 to output 3 13 dmod \ set D13 to output </pre> remap D15, D5, .. D13 <pre> create port-map 15 , 5 , 6 , 9 , 10 , 11 , 12 , 13 , : pin ( n -- n ) \ gets the Dx pin number cells port-map + @ ; </pre> <table> <tr> <td> <pre> : left ( -- ) 7 0 do 1 i pin dpin! 100 osDelay drop 0 i pin dpin! loop ; </pre> </td> <td> <pre> : right ( -- ) 8 1 do 1 8 i - pin dpin! 100 osDelay drop 0 8 i - pin dpin! loop ; </pre> </td> <td> <pre> : knigthrider ( -- ) begin left right key? until \ key pressed 0 0 dpin! key drop \ eat key ; </pre> </td> </tr> </table> Use the port pins on the lower row: <pre> 3 16 dmod \ set A0 to Output 3 17 dmod \ set A1 to Output 3 18 dmod \ set A2 to Output 3 19 dmod \ set A3 to Output 3 20 dmod \ set A4 to Output 3 21 dmod \ set A5 to output 3 2 dmod \ set D2 (SCK) to output 3 4 dmod \ set D4 (MOSI) to output </pre> remap D15, D5, .. D13 <pre> create port-map 16 , 17 , 18 , 19 , 20 , 21 , 2 , 4 , </pre> %DASHBOARD{ section="box_end" }% %DASHBOARD{ section="box_start" width="992" height="650" }% ---+ Using the ADC (Analog Input Pins) ---++ Control the Neopixel =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 neopixel blue led brightness. <pre> : neo-blue ( -- ) begin 0 apin@ 16 / neopixel! 10 osDelay drop key? until key drop ; </pre> ---++ Control the Knightrider Pace =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. <table> <tr> <td> <pre> : left ( -- ) 7 0 do 1 i pin dpin! 0 apin@ 10 / osDelay drop \ delay depends on A0 0 i pin dpin! loop ; </pre> </td> <td> <pre> : right ( -- ) 8 1 do 1 8 i - pin dpin! 0 apin@ 10 / osDelay drop \ delay depends on A0 0 8 i - pin dpin! loop ; </pre> </td> </tr> </table> %DASHBOARD{ section="box_end" }% %DASHBOARD{ section="box_start" width="992" height="400" }% ---+ Using the PWM (Analog Output Pins) Three port pins are supported so far. The 16 bit timer TIM1 (D0, D1, A4) 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. PWM port pins: D0 (!TIM1CH3), D1 (!TIM1CH2), and A4 (!TIM1CH1). Simple test program to set brightness of a LED on pin D0 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). <pre> 5 0 dmod \ set D0 to PWM : pwm ( -- ) begin 0 apin@ 4 / 0 pwmpin! 10 osDelay drop key? until key drop ; </pre> ---++ Control an RC Servo https://en.wikipedia.org/wiki/Servo_(radio_control): The control signal is a digital PWM signal with a 50 Hz frame rate. Within each 20 ms timeframe, an active-high digital pulse controls the position. The pulse nominally ranges from 1.0 ms to 2.0 ms with 1.5 ms always being center of range. Pulse widths outside this range can be used for "overtravel" - moving the servo beyond its normal range. A servo pulse of 1.5 ms width will typically set the servo to its "neutral" position (typically half of the specified full range), a pulse of 1.0 ms will set it to 0°, and a pulse of 2.0 ms to 90° (for a 90° servo). The physical limits and timings of the servo hardware varies between brands and models, but a general servo's full angular motion will travel somewhere in the range of 90° 180° and the neutral position (45° or 90°) is almost always at 1.5 ms. This is the "standard pulse servo mode" used by all hobby analog servos. The BSPs default PWM frequency is 1 kHz, 50 Hz is 20 times slower. The divider is therefore 32 * 20 = 640. | 0° | 1 ms | 50 | | 45° | 1.5 ms | 75 | | 90° | 2 ms | 100 | | 180° | 3 ms | 150 | | 270 | 4 ms | 200 | | 0° | 1 ms | 50 | | 90° | 1.5 ms | 75 | | 180° | 2 ms | 100 | | 270° | 2.5 ms | 150 | <pre> 640 pwmprescale 5 0 dmod \ set D0 to PWM : servo ( -- ) begin 130 40 do i 0 pwmpin! i neopixel! i 40 = if 1000 \ give some more time to get back else 200 then osDelay drop 10 +loop key? until key drop ; </pre> %DASHBOARD{ section="box_end" }% %DASHBOARD{ section="box_start" width="992" height="500" }% ---+ Using Input Capture and Output Compare ---++ Time Base Default timer resolution is 1 us. The 32 bit TIMER2 is used as time base for Input Capture / Output Compare. For a 5 s period 5'000'000 cycles are needed. All channels (input capture / output compare) use the same time base. <pre> : period ( -- ) 5000000 ICOCperiod! \ 5 s period ICOCstart begin waitperiod cr .time key? until key drop ; </pre> ---++ Output Compare Output compare TIM2: D5, D6, and D13 <pre> 7 5 dmod \ output compare for D5 7 6 dmod \ output compare for D6 7 13 dmod \ output compate for D13 : oc-toggle ( -- ) 5000000 ICOCperiod! \ 5 s period ICOCstart 3 5 OCmod 1000000 5 OCstart \ toggle D5 after 1 s 3 6 OCmod 2000000 5 OCstart \ toggle D6 after 2 s 3 13 OCmod 3000000 13 OCstart \ toggle D13 after 3 s begin waitperiod cr .time key? until key drop ; </pre> When you abort (hit any key) the program, the timer still runs and controls the port pins. To stop the port pins: <pre> 5 OCstop 5 OCstop 13 OCstop </pre> Or change the prescale to make it faster or slower: <pre> 1 ICOCprescale </pre> ---++ Input Capture This sample program measures the time between the edges on port A5. if no event occurs within 2 seconds, "timeout" is issued. Hit any key to abort program. <pre> : ic-test ( -- ) 6 21 dmod \ input capture on A5 ICOCstart 2 ICstart \ both edges ICOCcount@ ( -- count ) begin 2000 \ 2 s timeout ICwait ( -- old-capture capture ) cr dup 0= if ." timeout" drop else dup rot ( -- capture capture old-capture ) - 1000 / . ." ms" then key? until key drop drop ICstop ; </pre> ---++ Use Ouput Compare for PWM %DASHBOARD{ section="box_end" }% %DASHBOARD{ section="box_start" width="992" height="400" }% ---+ Using EXTI line D5, D6, D11 and D13 can be used as an EXTI line. EXTIs are external interrupt lines, D5 uses EXTI2 (EXTI Line2 interrupt), D6 EXTI3, D11 EXIT8, and D13 EXTI1. <pre> : exti-test ( -- ) 2 5 EXTImod \ both edges on D5 begin 2000 5 EXTIwait \ wait for edge on D5 (button C) with 2 s timeout cr 0= if 5 dpin@ if ." rising edge" else ." falling edge" then else ." timeout" then key? until key drop ; </pre> %DASHBOARD{ section="box_end" }% %DASHBOARD{ section="box_start" width="992" height="800" }% ---+ Pinouts This BSP is using the standard Feather numbering scheme and not the Argon numbering scheme. The red LED should be connected to D13, but it is connected to D12 (D7 in Argon numbering scheme). <pre> SCL D15, SDA D14 SCK D2, MO D4, MI D3, RX D0, TX D1 </pre> The anlog pins can be used as digital pins too: <pre> A0 D16, A1 D17, A2 D18, A3 D19, A4 D20, A5 D21 </pre> * Feather specification https://learn.adafruit.com/adafruit-feather/feather-specification * Particle Argon has a different numbering scheme for the for digital pins https://docs.particle.io/assets/images/argon/argon-pinout-v1.0.pdf | *Feather Left* | *Feather Connector* | *WB Feather* | *WB Connector* | *WB Port* | | Reset | JP1.16 | \RESET | J1.16 | | | 3.3 V | JP1.15 | 3V3 | J1.15 | | | Aref or Mode | JP1.14 | \MODE MCU_USER | J1.14 | PH3 | | GND | JP1.13 | GND | J1.13 | | | A0 (D16) | JP1.12 | A0 | J1.12 | PA4 | | A1 (D17) | JP1.11 | A1 | J1.11 | PA5 | | A2 (D18) | JP1.10 | A2 | J1.10 | PA6 | | A3 (D19) | JP1.9 | A3 | J1.9 | PA7 | | A4 or D24 (D20) | JP1.8 | A4 | J1.8 | PA8 | | A5 or D25 (D21) | JP1.7 | A5 | J1.7 | PA0 | | SCK or D2 | JP1.6 | SCK | J1.6 | PB3 | | MOSI or D4 | JP1.5 | MOSI | J1.5 | PB5 | | MISO or D3 | JP1.4 | MISO | J1.4 | PB4 | | RX or D0 | JP1.3 | RX | J1.3 | PA10 | | TX or D1 | JP1.2 | TX | J1.2 | PA9 | | * | JP1.1 | NC | J1.1 | | | *Feather Right* | *Feather Connector* | *WB Feather* | *WB Connector* | *WB Port* | | Bat | JP3.1 | LIPO+ | J2.12 | | | En | JP3.2 | EN (3.3 V) | J2.11 | | | USB | JP3.3 | VBUS | J2.10 | | | D13 red LED | JP3.4 | D8 | J2.9 | PA1 | | D12 | JP3.5 | D7 red LED | J2.8 | PB2 | | D11 | JP3.6 | D6 | J2.7 | PB8 | | D10 | JP3.7 | D5 | J2.6 | PB9 | | D9 | JP3.8 | D4 | J2.5 | PB1 | | D6 | JP3.9 | D3 | J2.4 | PA3 | | D5 | JP3.10 | D2 | J2.3 | PA2 | | SCL or D15 | JP3.11 | SCL | J2.2 | PB6 | | SDA or D14 | JP3.12 | SDA | J2.1 | PB7 | ---++ Digital Pins ---+++ JP1.1 NC ---+++ RESET/ JP1.16 ---+++ UART_RX / GPIO D0 / PA10 / JP1.3 * Receive (input) pin for USART1 * PWM out on TIM2_CH3 ---+++ UART_TX / GPIO D1 / PA9 / JP1.2 * Transmit (output) pin for USART1 * PWM out on TIM2_CH2 ---+++ SCK / GPIO D2 / PB3 / JP1.6 * The SPI bus clock pin. Hardware SPI1 * PWM out on TIM1_CH2 ---+++ MISO / GPIO D3 / PB4 / JP1.4 * The SPI bus clock pin. Hardware SPI1 ---+++ MOSI / GPIO D4 / PB1 / JP1.5 * The SPI bus clock pin. Hardware SPI2 ---+++ GPIO D5 / Button C / PA2 / JP3.10 * PWM out on TIM2_CH3 * Alternate uses: LPUART1 TX, I2S3 MCK ---+++ GPIO D6 / Button B / PB8 / JP3.9 * PWM out on TIM3_CH1 * Alternate uses: LPUART1 RX ---+++ GPIO D7 * - ---+++ GPIO D8 * - ---+++ GPIO D9 / Button A / PB1 / JP3.8 ---+++ GPIO D10 / PB9 / JP3.7 * PWM out on TIM1_CH3N * Alternate uses: I2C1_SDA ---+++ GPIO D11 / PB8 / JP3.6 * PWM out on TIM1_CH2N * Alternate uses: I2C1_SCL ---+++ GPIO D12 / red LED / PB2 / JP3.5 * Connected to the red LED next to the USB jack ---+++ GPIO D13 / (red LED) / PA1 / JP3.4 * (Connected to the red LED next to the USB jack) * PWM out on TIM2_CH2 ---+++ SDA / GPIO D14 / PB7 / JP3.12 * The I2C (Wire) data pin, this has a 10K pullup to 3.3V. Hardware I2C1 * Alternate uses: USART1 RX ---+++ SCL / GPIO D15 / PB6 / JP3.11 * the I2C (Wire) clock pin, this has a 10K pullup to 3.3V. Hardware I2C1 * Alternate uses: USART1 TX ---++ Analog Pins ---+++ A0 / GPIO 16 / PA4 / JP1.12 * This pin is analog input A0 (ADC12 IN4) * Analog output (DAC OUT1) due to having a DAC (digital-to-analog converter). You can set the raw voltage to anything from 0 to 3.3V, unlike PWM outputs this is a true analog output * No PWM or alternate uses ---+++ A1 / GPIO 17 / PA5 / JP1.11 * This pin is analog input A1 (ADC12 IN5) * Analog output (DAC OUT2) due to having a DAC (digital-to-analog converter). This is the second DAC, and is 'independent' of A0. You can set the raw voltage to anything from 0 to 3.3V, unlike PWM outputs this is a true analog output. * Alternative uses: SPI1 SCK ---+++ A2 / GPIO18 / PA6 / JP1.10 * This pin is analog input A2 (ADC12 IN6) * Alternative uses: SPI1 MISO * PWM out on TIM2_CH2 ---+++ A3 / GPIO19 / PA7 / JP1.9 * This pin is analog input A3 (ADC12 IN7) * Alternative uses: SPI1 MOSI * PWM out on TIM3_CH2 ---+++ A4 / GPIO20 / PA8 / JP1.8 * This pin is analog input A4 () ---+++ A5 / GPIO21 / PA0 / JP1.7 * This pin is analog input A5 (5) ---++ SPI Flash ---+++ FLASH_SCK / PB3 ---+++ FLASH_MISO / PB4 ---+++ FLASH_MOSI / PB5 ---+++ FLASH_CS / PA15 ---++ USB ---+++ USB_DP / PA12 ---+++ USB_DM / PA11 ---++ Antenna ---+++ CTRL_FE1 / PE4 Low chip antenna, high UFL connectot ---+++ CTRL_FE2 / PB0 VDD for HF switch. %DASHBOARD{ section="box_end" }% %DASHBOARD{ section="dashboard_end" }% -- %USERSIG{PeterSchmid - 2020-06-10}% <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/88x31.png" /></a><br />This work by <a xmlns:cc="http://creativecommons.org/ns#" href="http://spyr.ch" property="cc:attributionName" rel="cc:attributionURL">Peter Schmid</a> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/">Creative Commons Attribution-ShareAlike 4.0 International License</a>.
Attachments
Attachments
Topic attachments
I
Attachment
History
Action
Size
Date
Who
Comment
jpg
WB_Feather_header.jpg
r1
manage
83.5 K
2021-06-25 - 08:41
PeterSchmid
jpg
WB_Feather_oled_sdcard.jpg
r1
manage
382.8 K
2021-06-25 - 08:41
PeterSchmid
This topic: MecrispCube
>
WebHome
>
BoardSupportPackageWBfeather
Topic revision: r24 - 2022-04-29 - PeterSchmid
Copyright © 2008-2025 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback