 |
Arduino Core for STM32
1.0
|
Go to the documentation of this file.
11 #if defined(STM32F030x6)
12 #include <stm32f030x6.h>
13 #include "stm32f0xx_hal.h"
14 #define LED_BUILTIN (PA2)
16 #elif defined(STM32F070x6)
17 #include <stm32f070x6.h>
18 #include "stm32f0xx_hal.h"
20 #elif defined(STM32F070xB)
21 #include <stm32f070xb.h>
22 #include "stm32f0xx_hal.h"
24 #elif defined(STM32F031x6)
25 #include <stm32f031x6.h>
26 #include "stm32f0xx_hal.h"
28 #elif defined(STM32F103xB)
29 #include <stm32f103xb.h>
30 #include "stm32f1xx_hal.h"
31 #define LED_BUILTIN (PC13)
33 #elif defined(STM32L031xx)
34 #include <stm32l031xx.h>
35 #include "stm32l0xx_hal.h"
36 #define LED_BUILTIN (PB3)
60 #elif defined(STM32L432xx)
61 #include <stm32l432xx.h>
62 #include "stm32l4xx_hal.h"
63 #define LED_BUILTIN (PB3)
88 #error "Library for your chip is not included"
91 #if defined(USE_HAL_DRIVER) && !defined(STM32)
95 #if !defined(HAL_GPIO_MODULE_ENABLED)
96 #error "GPIO is disabled in .ioc file, modify at least one pin to use wirish file"
100 #ifndef W_INT_HANDLING_MODE
104 #define W_INT_HANDLING_MODE 2
109 #include <functional>
457 #if defined(GPIOL) || defined(GPIOM) || defined(GPION) || defined(GPIOO) || defined(GPIOP) || defined(GPIOQ) || defined(GPIOR) || defined(GPIOS) || defined(GPIOT) || defined(GPIOU) || defined(GPIOV) || defined(GPIOW) || defined(GPIOX) || defined(GPIOY) || defined(GPIOZ)
458 #warning "Some GPIOx ports have not got defined pin names!"
535 bool pinExists(GPIO_TypeDef *GPIOx, uint16_t PPin);
550 bool enableGPIO(GPIO_TypeDef* GPIOx,
bool enable);
557 #define PIN_TO_PORT_PIN(Pin) (0x01 << ((Pin)&0x0F)) //Arduino like pin to Pin of port
564 #define PIN_TO_PORT(Pin) (GPIO_Conversion_Table[(Pin)>>4]) //Arduino like pin to Port
626 inline void digitalWrite(GPIO_TypeDef *GPIOx, uint16_t PPin,
bool val){
627 HAL_GPIO_WritePin(GPIOx, PPin, (GPIO_PinState)val);
637 return (uint16_t)HAL_GPIO_ReadPin(GPIOx, PPin);
646 HAL_GPIO_TogglePin(GPIOx, PPin);
669 return pinMode(Pin, mode, GPIO_SPEED_FREQ_LOW);
690 assert_param(IS_GPIO_PIN_AVAILABLE(GPIOx, PPin));
691 return (GPIOx->IDR & PPin) != (uint32_t)GPIO_PIN_RESET;
712 int8_t
attachInterrupt(uint8_t Pin, std::function<
void(
void)>,
int mode);
722 int8_t
detachInterrupt(uint8_t Pin,
bool disableEXTIwhenNotUsed =
false);
769 #define MIN(a,b) (((a)<(b))?(a):(b))
778 #define MAX(a,b) (((a)>(b))?(a):(b))
787 #define Abs(a) (((a)>=0)?(a):-(a))
796 #define lowByte(w) ((w) & 0xFF)
803 #define highByte(w) (((w) >> 8) & 0xFF)
811 #define bitRead(value, bit) (((value) >> (bit)) & 0x01)
819 #define bitSet(value, bit) ((value) |= (1UL << (bit)))
827 #define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
836 #define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : \
837 bitClear(value, bit))
844 #define bit(b) (1UL << (b))
851 #define millis() HAL_GetTick()
860 #define delay(millis) HAL_Delay(millis)
874 #define WAIT_US_CALIBRATION (18) //It says, how many cycles (Not clock cycles) are used by calling this functions
879 #if defined(DWT) || defined(DOXYGEN_FORCED) //We can use Data Watchpoint and Trace Register (DWT) and it's cycle counter
888 void __attribute__((optimize(
"Ofast"))) delayMicrosecondsDWT(uint32_t microseconds);
889 #endif //defined(DWT) || defined(DOXYGEN_FORCED)
899 void __attribute__((optimize(
"Ofast"))) delayMicroseconds(int32_t microseconds);
911 uint32_t load = SysTick->LOAD;
912 volatile uint32_t ms = uwTick;
913 uint32_t initVal = SysTick->VAL;
916 initVal = SysTick->VAL;
919 return ms*1000UL + ((load-initVal)*1000)/(load+1);
929 inline uint64_t
__attribute__((optimize(
"Ofast"))) micros64(){
934 uint32_t load = SysTick->LOAD;
935 volatile uint32_t ms = uwTick;
936 uint32_t initVal = SysTick->VAL;
939 initVal = SysTick->VAL;
942 return ((uint64_t)ms)*1000ULL + (((uint64_t)(load-initVal))*1000ULL)/(load+1);
949 #define cli() __disable_irq()
957 #define noInterrupts() cli()
959 #define sei() __enable_irq()
967 #define interrupts() sei()
978 unsigned long random(
unsigned long from,
unsigned long to);
985 unsigned long random(
unsigned long to);
1034 #ifndef RCC_FLAG_PORRST
1036 #define RESET_CAUSE_POWER_ON_POWER_DOWN_RESET RESET_CAUSE_EXTERNAL_RESET_PIN_RESET
1053 #ifdef RCC_FLAG_PORRST
1061 #ifdef RCC_FLAG_FWRST
1063 RESET_CAUSE_FIREWALL_RESET = 8,
1065 #ifdef RCC_FLAG_OBLRST
1067 RESET_CAUSE_OPT_BYTE_LDR_RESET = 9,
1093 buffer[0] = *((
const char*) (UID_BASE + 5));
1094 buffer[1] = *((
const char*) (UID_BASE + 6));
1095 buffer[2] = *((
const char*) (UID_BASE + 7));
1097 buffer[4] = *((
const char*) (UID_BASE + 8));
1098 buffer[5] = *((
const char*) (UID_BASE + 9));
1099 buffer[6] = *((
const char*) (UID_BASE + 10));
1109 return *((
volatile uint8_t *)(UID_BASE + 4));
1117 return *((
volatile uint16_t *)(UID_BASE));
1125 return *((
volatile uint16_t *)(UID_BASE + 2));
1133 return *((
volatile uint16_t *)(FLASHSIZE_BASE)) * 1024;
@ INPUT_PULLUP
The state of the pin in this mode is reported the same way as with INPUT, but the pin voltage is gent...
Definition: wirish.h:500
#define RESET_CAUSE_POWER_ON_POWER_DOWN_RESET
Power-ON reset, Power-DOWN reset cause.
Definition: wirish.h:1036
uint32_t getPinPullSetting(GPIO_TypeDef *GPIOx, uint8_t INTPin)
This function should return actual pin pull setting (GPIO_NOPULL, GPIO_PULLUP, GPIO_PULLDOWN)
Definition: wirish.cpp:581
uint32_t getPinSpeedSetting(GPIO_TypeDef *GPIOx, uint8_t INTPin)
This should return actual pin toggle speed setting.
Definition: wirish.cpp:628
@ OUTPUT_OPEN_DRAIN
In open drain mode, the pin indicates "low" by accepting current flow to ground and "high" by providi...
Definition: wirish.h:471
reset_cause_e
Possible STM32 system reset causes.
Definition: wirish.h:1042
#define PIN_TO_PORT(Pin)
Converts Arduino like pin number (Pin) to GPIO port.
Definition: wirish.h:564
@ INPUT
Basic digital input.
Definition: wirish.h:487
@ RESET_CAUSE_UNKNOWN
Unknown reset cause.
Definition: wirish.h:1044
@ RESET_CAUSE_INDEPENDENT_WATCHDOG_RESET
Independent watchdog reset cause.
Definition: wirish.h:1050
@ INPUT_ANALOG
This is a special mode for when the pin will be used for analog (not digital) reads.
Definition: wirish.h:495
@ RESET_CAUSE_WINDOW_WATCHDOG_RESET
Window watchdog reset cause.
Definition: wirish.h:1048
ResetCause rst_cs
Definition: wirish.cpp:1134
GPIO_TypeDef * GPIO_Conversion_Table[]
Definition: wirish.cpp:13
bool enableGPIO(GPIO_TypeDef *GPIOx, bool enable)
Enables/Disables GPIO port periphery.
Definition: wirish.cpp:309
void randomSeed(unsigned long seed)
Initializes the pseudo-random number generator, causing it to start at an arbitrary point in its rand...
Definition: wirish.cpp:1029
void getDeviceLOTID(char *buffer)
Returns device LOT ID as text.
Definition: wirish.h:1092
This file contains override weak GPIO interrupt functions.
@ RESET_CAUSE_LOW_POWER_RESET
Low power reset cause.
Definition: wirish.h:1046
enum reset_cause_e ResetCause
Possible STM32 system reset causes.
bool pinExists(GPIO_TypeDef *GPIOx, uint16_t PPin)
Checks if pin is available on MCU.
Definition: wirish.cpp:73
unsigned long random(unsigned long from, unsigned long to)
The random function generates pseudo-random numbers.
Definition: wirish.cpp:1013
uint32_t getFlashSize()
Gets flash size in bytes.
Definition: wirish.h:1132
void InterruptHandler(uint8_t lineFrom, uint8_t lineTo)
Include this in every EXTI interrupt handler for lines 0-15.
Definition: wirish.cpp:908
uint8_t getDeviceWAFID()
Gets device wafer plate ID.
Definition: wirish.h:1108
@ RESET_CAUSE_SOFTWARE_RESET
Software reset cause.
Definition: wirish.h:1052
@ OUTPUT
Basic digital output: when the pin is HIGH, the voltage is held at +3.3v (Vcc) and when it is LOW,...
Definition: wirish.h:467
GPIO_TypeDef * getInterruptGPIOfromPin(uint16_t Pin)
Gets, what GPIO is attached to EXTI line, that belongs to PPin.
Definition: wirish.cpp:471
uint16_t getDeviceWAFX()
Returns device wafer plate X coordination.
Definition: wirish.h:1116
uint16_t getDeviceWAFY()
Gets device wafer plate Y coordination.
Definition: wirish.h:1124
@ INPUT_FLOATING
Synonym for INPUT.
Definition: wirish.h:516
void __attribute__((optimize("Ofast"))) delayMicrosecondsDWT(uint32_t microseconds)
Pauses the program for the amount of time (in microseconds) specified as parameter.
Definition: wirish.h:906
uint8_t PortAndPinToPinNum(GPIO_TypeDef *GPIOx, uint16_t PPin)
Converts GPIOx port and it's pin to Arduino like pin number.
Definition: wirish.cpp:176
uint16_t digitalRead(GPIO_TypeDef *GPIOx, uint16_t PPin)
Reads state of pin or multiple pins.
Definition: wirish.h:636
@ INPUT_PULLDOWN
The state of the pin in this mode is reported the same way as with INPUT, but the pin voltage is gent...
Definition: wirish.h:508
uint8_t pinMode(GPIO_TypeDef *GPIOx, uint16_t PPin, WiringPinMode mode, uint32_t speed)
Sets mode of selected pin.
Definition: wirish.cpp:250
bool canSetInterruptOnPin(uint8_t Pin)
Checks if EXTI line, that belongs to Pin is not used by other pin's interrupt.
Definition: wirish.cpp:459
#define PIN_TO_PORT_PIN(Pin)
Converts Arduino like pin number (Pin) to Pin of port (PPin).
Definition: wirish.h:557
void digitalWrite(GPIO_TypeDef *GPIOx, uint16_t PPin, bool val)
Writes new state to pin or multiple pins.
Definition: wirish.h:626
@ RESET_CAUSE_BROWNOUT_RESET
Brownout reset cause.
Definition: wirish.h:1060
bool WirishInit(void)
Initializes some wirish functions.
Definition: wirish.cpp:931
int8_t detachInterrupt(uint8_t Pin, bool disableEXTIwhenNotUsed=false)
Detaches interrupt from selected pin and sets pin mode to INPUT.
Definition: wirish.cpp:738
void digitalToggle(GPIO_TypeDef *GPIOx, uint16_t PPin)
Toggles pin state.
Definition: wirish.h:645
ResetCause getResetCause()
Reads the STM32 system reset cause.
Definition: wirish.h:1084
int8_t attachInterrupt(uint8_t Pin, std::function< void(void)>, int mode)
Attaches interrupt to selected pin.
Definition: wirish.cpp:669
const char * getResetCauseName()
Gets the system reset cause as an ASCII-printable name string from a reset cause type.
Definition: wirish.cpp:1088
int8_t isPinUsedByInt(uint8_t INTPPin)
Checks if pin is not used for interrupt.
WiringPinMode
Pin mode enumerations.
Definition: wirish.h:466
@ RESET_CAUSE_EXTERNAL_RESET_PIN_RESET
External reset pin reset cause.
Definition: wirish.h:1058
bool isInterruptSetOnPin(uint8_t Pin)
Checks Pin is used as interrupt.
Definition: wirish.cpp:557