STM32F302x8 IO¶
Below are the currently supported IO interfaces of EVT-core on the STM32F302x8.
ADC¶
CAN¶
-
class EVT::core::IO::CANf302x8 : public EVT::core::IO::CAN¶
STMF302x8 implementation of the CAN protocol.
The STM32f302x8 has an on board CAN controller which adds additional features.
Ability to generate interrupts which allows users to add custom call backs
Hardware based message filtering which allows the filtering of messages to be handled by hardware not software.
Public Functions
-
CANf302x8(Pin txPin, Pin rxPin, bool loopbackEnabled = false)¶
Create a new instance of an STM32f302x8 CAN interface.
-
virtual void transmit(CANMessage &message)¶
Send a message over CAN.
- Parameters
message[in] – The message to send over CAN.
-
virtual CANMessage *receive(CANMessage *message, bool blocking = false)¶
Receive a message over CAN.
The user can either receive in blocking or non-blocking mode. In blocking mode, the code will hang until a message is received then return a pointer to the message that was passed in. In non-blocking, a nullptr will be returned if no message is currently in the mailbox.
NOTE: If you add your own custom callback. This method will alway return a nullptr. If you leave this as blocking, then the program will always block.
- Parameters
message[out] – The message to populate with data
blocking[in] – Used to determine if received should block or not, by default receive is blocking
- Returns
A pointer to the passed in message, nullptr if message not received.
GPIO¶
-
class EVT::core::IO::GPIOf302x8 : public EVT::core::IO::GPIO¶
Public Functions
-
GPIOf302x8(Pin pin)¶
Create an instance of the STMF3xx GPIO pin using the provided pin.
The direction will have to be set manually before use.
pin[in] The pin for the GPIO instance to use.
-
GPIOf302x8(Pin pin, Direction direction)¶
Create an instance of the STMF3xx GPIO pin using the provided pin and direction.
- Parameters
pin[in] – The pin for the GPIO instance to use.
direction[in] – The flow of data (either input or output).
-
virtual void setDirection(Direction direction)¶
Set the direction of the pin.
- Parameters
direction[in] – The direction of information.
-
virtual void writePin(State state)¶
Used for writing a state to a pin.
- Parameters
state[in] – The sate to write to the pin.
-
virtual State readPin()¶
Used for reading the state of the pin.
- Returns
The state of the pin.
-
GPIOf302x8(Pin pin)¶
I2C¶
-
class EVT::core::IO::I2Cf302x8 : public EVT::core::IO::I2C¶
Public Functions
-
I2Cf302x8(Pin sclPin, Pin sdaPin)¶
Make an instance of an I2C interface for the F3.
Will determine which I2C bus of the STM to use based on the provided pins.
-
virtual uint8_t read(uint8_t addr)¶
Read a single byte back from the I2C bus.
- Parameters
addr[in] – The 7 bit unshifted I2C address to read from.
- Returns
The byte read from the address.
-
void write(uint8_t addr, uint8_t *bytes, uint8_t length)¶
Write out multiple bytes over I2C.
Each byte will be written one by one.
-
void read(uint8_t addr, uint8_t *bytes, uint8_t length)¶
Read multiple bytes from an I2C device.
- Parameters
addr[in] – The 7 bit unshifted I2C address to write to
bytes[out] – The buffer to fill with the read in bytes.
length[in] – The number of bytes to read.
-
void writeReg(uint8_t addr, uint8_t reg, uint8_t byte)¶
Write a value to a register has that 8 bit addresses and 8 bit values.
- Parameters
addr[in] – The 7 bit unshifted I2C address to write to.
reg[in] – The 8 bit register
byte[in] – The byte to write out
-
uint8_t readReg(uint8_t addr, uint8_t reg)¶
Read a value from a register that has an 8 bit address and 8 bit value.
- Parameters
addr[in] – The 7 bit unshifted I2C address to read from.
reg[in] – The 8 bit register
- Returns
The 8 bit value of the register.
-
void writeReg(uint8_t addr, uint8_t *reg, uint8_t regLength, uint8_t *bytes, uint8_t length)¶
Write out a multi byte register value.
- Parameters
addr[in] – The 7 bit unshifted I2C address to write to
reg[in] – The register bytes
regLength[in] – The number of bytes in the register address
bytes[in] – The data to write out
length[in] – The number of bytes in the data
-
void readReg(uint8_t addr, uint8_t *reg, uint8_t regLength, uint8_t *bytes, uint8_t length)¶
Read a value from a register.
- Parameters
addr[in] – The 7 bit unshifted I2C address to read from.
reg[in] – The bytes containing the register to read from
regLength[in] – The size in bytes of the register
bytes[out] – The bytes read from the register
length[in] – The size of the data returned by the register in bytes
-
I2Cf302x8(Pin sclPin, Pin sdaPin)¶
PWM¶
-
class EVT::core::IO::PWMf302x8 : public EVT::core::IO::PWM¶
Public Functions
-
PWMf302x8(Pin pin)¶
Setup the given pin for PWM usage.
- Parameters
pin[in] – The pin to setup for PWM
-
virtual void setDutyCycle(float dutyCycle)¶
Set the duty cycle for the pin to operate at.
- Parameters
dutyCycle[in] – Duty cycle to set the pin to.
-
virtual void setPeriod(float period)¶
Set the period for the PWM.
- Parameters
period[in] – The period of the PWM in seconds.
-
PWMf302x8(Pin pin)¶
UART¶
-
class EVT::core::IO::UARTf302x8 : public EVT::core::IO::UART¶
Public Functions
-
UARTf302x8(Pin txPin, Pin rxPin, uint32_t baudrate)¶
Create an instance of the STMF302x8 UART interface using the provided TX and RX pins.
-
virtual void setBaudrate(uint32_t baudrate)¶
Set the baudrate that the UART will operate with.
- Parameters
baudrate[in] – The new baudrate to use
-
virtual void setFormat(WordLength wordLength = WordLength::EIGHT, Parity parity = Parity::NONE, NumStopBits numStopBits = NumStopBits::ONE)¶
Set the format that data will be communicated with over UART.
DEFAULT: 8 bit words, no parity, 1 stop bit
- Parameters
wordLength[in] – The number of bits in a work (5-8)
parity[in] – The parity settings to use.
numStopBits[in] – The number of stop bits (1-2)
-
virtual bool isReadable()¶
Determins if the UART is currently readable.
- Returns
True if the UART is readable.
-
virtual bool isWritable()¶
Determins if the UART is currently writable.
- Returns
True if the UART is writable
-
virtual void putc(char c)¶
Put a single character to the UART module.
- Parameters
c[in] – The character to send over UART.
-
virtual void puts(const char *s)¶
Put a null-terminal string out over UART.
- Parameters
s[in] – The null-terminated string to put over UART.
-
virtual char getc()¶
Blocking call to read a single character from the UART module.
- Returns
The character read in over UART.
-
virtual void printf(const char *format, ...)¶
Print a formatted string over UART, not great performance so best in test situations not production.
- Parameters
format[in] – The format string to print out.
-
virtual void write(uint8_t byte)¶
Write out a single byte over UART.
- Parameters
byte[in] – The byte to write out over UART.
-
virtual uint8_t read()¶
Blocking reading of a single byte from the UART.
- Returns
The byte read in from UART.
-
UARTf302x8(Pin txPin, Pin rxPin, uint32_t baudrate)¶