Skip to content

Commit

Permalink
feat: Add STM32Cube HAL getter to SPI, Wire and HardwareSerial
Browse files Browse the repository at this point in the history
Could be used for example to mix Arduino API and STM32Cube HAL API.
For example to configure DMA.
Warning: Use at your own risk

Fixes stm32duino#1035

Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com>
  • Loading branch information
ABOSTM committed Mar 9, 2022
1 parent 67a5298 commit 0d22157
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cores/arduino/HardwareSerial.h
Expand Up @@ -174,6 +174,13 @@ class HardwareSerial : public Stream {
// Interrupt handlers
static void _rx_complete_irq(serial_t *obj);
static int _tx_complete_irq(serial_t *obj);

// Could be used to mix Arduino API and STM32Cube HAL API (ex: DMA). Use at your own risk.
UART_HandleTypeDef* getHandle(void)
{
return &(_serial.handle);
}

private:
bool _rx_enabled;
uint8_t _config;
Expand Down
6 changes: 6 additions & 0 deletions libraries/SPI/src/SPI.h
Expand Up @@ -227,6 +227,12 @@ class SPIClass {
void attachInterrupt(void);
void detachInterrupt(void);

// Could be used to mix Arduino API and STM32Cube HAL API (ex: DMA). Use at your own risk.
SPI_HandleTypeDef* getHandle(void)
{
return &(_spi.handle);
}

private:
/* Contains various spiSettings for the same spi instance. Each spi spiSettings
is associated to a CS pin. */
Expand Down
6 changes: 6 additions & 0 deletions libraries/Wire/src/Wire.h
Expand Up @@ -130,6 +130,12 @@ class TwoWire : public Stream {
return write((uint8_t)n);
}
using Print::write;

// Could be used to mix Arduino API and STM32Cube HAL API (ex: DMA). Use at your own risk.
I2C_HandleTypeDef* getHandle(void)
{
return &(_i2c.handle);
}
};


Expand Down

0 comments on commit 0d22157

Please sign in to comment.