Koduino
Functions
Pin configuration

Detailed Description

Usage

  1. (Optionally) call pinRemap() to remap the AF or timer connected to a pin
  2. Call pinMode() with any supported #WiringPinMode

Pin assignment defaults

The STM32 series allows multiplexing its pins for various purposes, but the procedure for doing so requires selecting a special "alternate function" (AF) number for the pin. This number has to be looked up from the datasheet.

There are some default assignments for all the pins which are linked to below for different variants:

Pin remapping

However, other assignments are possible, and the function pinRemap() can be called to do this. A common use case is changing the timer a pin is connected to (see example below).

Example: changing connected timer

#include <Arduino.h>
void setup() {
// Non Arduino-like function to assign a different timer to PB6
pinRemap(PB6, 11, TIMER19, 1);
// Arduino-like configuration for PWM
analogWriteFrequency(PB6, 25000);
// Unlike in Arduino, this *MUST* be called before analogWrite()
pinMode(PB6, PWM);
}
void loop() {
// 75% duty cycle PWM at 25 KHz
analogWrite(PB6, 0.75);
}
Authors
Avik De avikd.nosp@m.e@gm.nosp@m.ail.c.nosp@m.om

This file is part of koduino https://github.com/avikde/koduino

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, see http://www.gnu.org/licenses/.

Functions

void pinMode (uint8_t pin, WiringPinMode mode)
 Configure a pin before using it. More...
 
void pinRemap (uint8_t pin, uint8_t altFunc, uint8_t timer, uint8_t channel)
 Low-level function to reassign AF number of timer assigned to a pin. The default assignments are here. More...
 
void pinModeAlt (uint8_t pin, uint32_t oType, uint32_t pull, uint8_t altFunc)
 Low-level function to configure the pin for a specific alternate function. The user should not need to call this directly. More...
 

Function Documentation

void pinMode ( uint8_t  pin,
WiringPinMode  mode 
)

Configure a pin before using it.

This function behaves like the Arduino one, but does more in some cases.

In a few situations, this MUST be called in this library when it is not necessary to in Arduino. For instance, a timer pin must be configured for PWM using pinMode(pin, PWM) before calling analogWrite() on that pin.

Parameters
pinPin to configure
modeOne of #WiringPinMode
void pinModeAlt ( uint8_t  pin,
uint32_t  oType,
uint32_t  pull,
uint8_t  altFunc 
)

Low-level function to configure the pin for a specific alternate function. The user should not need to call this directly.

Parameters
pinPin to configure
oTypeOne of GPIO_OType_PP, GPIO_OType_OD
pullOne of GPIO_PuPd_NOPULL, GPIO_PuPd_UP, GPIO_PuPd_DOWN
altFuncAF number between 0-15 (see datasheet)
void pinRemap ( uint8_t  pin,
uint8_t  altFunc,
uint8_t  timer,
uint8_t  channel 
)

Low-level function to reassign AF number of timer assigned to a pin. The default assignments are here.

Parameters
pin
altFuncNew AF number (0-15)
timerNew timer (see variant.cpp for the variant you are using to see available timers)
channelTimer channel (1-4)