STM32F302x8 IO

Below are the currently supported IO interfaces of EVT-core on the STM32F302x8.

ADC

class EVT::core::IO::ADCf302x8 : public EVT::core::IO::ADC

Public Functions

ADCf302x8(Pin pin)

Setup the given pin for ADC usage.

Parameters

pin[in] – The pin to setup for ADC

virtual float read()

Read the value on the ADC in volts.

Returns

The voltage in volts

virtual uint32_t readRaw()

Read the raw value from the ADC.

Returns

The raw value from the ADC

virtual float readPercentage()

Read the value from the ADC as a percentage of the possible values from 0 to 1.

This is based on the maximum possible value the ADC can read.

Returns

The ADC value as a percentage

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.

  1. Ability to generate interrupts which allows users to add custom call backs

  2. 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.

Parameters
  • txPin[in] – The pin to trasmit CAN messages on

  • rxPin[in] – The pin to receive CAN messages on

  • loopbackEnabled[in] – Flag for enabling CAN loop back

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.

virtual void registerIRQ(TriggerEdge edge, void (*irqHandler)(GPIO *pin)) override

Used to register an IRQ Handler for the GPIO instance.

Parameters
  • edge[in] – the trigger edge

  • irqHandler[in] – the function pointer to the handler

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.

Parameters
  • sclPin[in] – The I2C clock pin

  • sdaPin[in] – The I2C data pin

virtual void write(uint8_t addr, uint8_t byte)

Write a single byte out over I2C.

Parameters
  • addr[in] – The 7 bit unshifted I2C address to write to

  • byte[in] – The value to write over I2C.

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.

Parameters
  • addr[in] – The 7 bit unshifted I2C address to write to.

  • bytes[in] – The bytes to write out over I2C.

  • length[in] – The number of bytes to write out.

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

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.

virtual float getDutyCycle()

Get the current duty cycle.

Returns

The duty cycle the PWM is operating at.

virtual uint32_t getPeriod()

Get the current period.

Returns

The period the PWM is operating at.

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.

Parameters
  • txPin[in] – The UART TX pin.

  • rxPin[in] – THe UART RX pin.

  • baudrate[in] – The baudrate to operate the UART with/

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 void sendBreak()

Sends a serial break condition over UART.

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.

virtual void writeBytes(uint8_t *bytes, size_t size)

Write an arbitrary number of bytes out over UART.

Parameters
  • bytes[in] – The data to send out over UART

  • size[in] – The number of bytes to send out over UART.

virtual void readBytes(uint8_t *bytes, size_t size)

Blocking reading of an arbitrary number of bytes in over UART.

Parameters
  • bytes[out] – The data buffer to fill

  • size[in] – The number of bytes to read in.