no-OS
stm32_spi.h
Go to the documentation of this file.
1 /***************************************************************************/
33 #ifndef STM32_SPI_H_
34 #define STM32_SPI_H_
35 
36 #include <stdint.h>
37 #include "no_os_spi.h"
38 #include "no_os_dma.h"
39 #include "no_os_gpio.h"
40 #include "stm32_hal.h"
41 #include "stm32_gpio.h"
42 #ifdef HAL_TIM_MODULE_ENABLED
43 #include "stm32_pwm.h"
44 #endif
45 
53  uint32_t chip_select_port;
55  uint32_t (*get_input_clock)(void);
57  uint32_t alternate;
64  uint32_t irq_num;
65 #ifdef HAL_TIM_MODULE_ENABLED
66 
67  const struct no_os_pwm_init_param *pwm_init;
68  const struct no_os_pwm_init_param *tx_pwm_init;
69 #endif
70 };
71 
78  SPI_HandleTypeDef hspi;
80  uint32_t input_clock;
82  uint32_t alternate;
94  void (*stm32_spi_dma_user_cb)(void *ctx);
98 #ifdef HAL_TIM_MODULE_ENABLED
99 
100  struct no_os_pwm_desc* pwm_desc;
101  struct no_os_pwm_desc* tx_pwm_desc;
102 #endif
103 };
104 
108 extern const struct no_os_spi_platform_ops stm32_spi_ops;
109 
110 #endif // STM32_SPI_H_
stm32_spi_init_param
Structure holding the initialization parameters for stm32 platform specific SPI parameters.
Definition: stm32_spi.h:51
stm32_spi_altrnate_cs_enable
int32_t stm32_spi_altrnate_cs_enable(struct no_os_spi_desc *desc, bool enable)
enable CS gpio alternate function
Definition: stm32_spi.c:301
no_os_gpio_desc::extra
void * extra
Definition: no_os_gpio.h:106
timeout
uint32_t timeout
Definition: ad413x.c:49
no_os_alloc.h
no_os_gpio_init_param
Structure holding the parameters for GPIO initialization.
Definition: no_os_gpio.h:79
no_os_pwm_init_param
Structure containing the init parameters needed by the PWM generator.
Definition: no_os_pwm.h:66
no_os_gpio_init_param::pull
enum no_os_gpio_pull_up pull
Definition: no_os_gpio.h:85
stm32_dma.h
Platform independent function definitions and data types for the DMA API.
no_os_spi_desc::device_id
uint32_t device_id
Definition: no_os_spi.h:196
stm32_spi_desc::stm32_spi_dma_done
bool stm32_spi_dma_done
Definition: stm32_spi.h:93
NO_OS_SPI_CPOL
#define NO_OS_SPI_CPOL
Definition: no_os_spi.h:48
stm32_spi_desc
stm32 platform specific SPI descriptor
Definition: stm32_spi.h:76
no_os_spi_init_param::bit_order
enum no_os_spi_bit_order bit_order
Definition: no_os_spi.h:150
stm32_gpio_desc::port
GPIO_TypeDef * port
Definition: stm32_gpio.h:59
no_os_spi.h
Header file of SPI Interface.
no_os_dma_init_param
Initialization parameter for the DMA controller.
Definition: no_os_dma.h:171
no_os_dma_ch::id
uint32_t id
Definition: no_os_dma.h:109
no_os_pwm_remove
int32_t no_os_pwm_remove(struct no_os_pwm_desc *desc)
Free the resources allocated by no_os_pwm_init().
Definition: no_os_pwm.c:79
stm32_spi_dma_transfer_sync
int32_t stm32_spi_dma_transfer_sync(struct no_os_spi_desc *desc, struct no_os_spi_msg *msgs, uint32_t len)
Configure and start a series of transfers using DMA. Wait for the completion before returning.
Definition: stm32_spi.c:672
no_os_spi_msg
Definition: no_os_spi.h:100
no_os_spi_platform_ops
Structure holding SPI function pointers that point to the platform specific function.
Definition: no_os_spi.h:222
no_os_dma_ch::irq_num
uint32_t irq_num
Definition: no_os_dma.h:115
no_os_delay.h
Header file of Delay functions.
stm32_spi_desc::tx_ch_xfer
struct stm32_dma_channel * tx_ch_xfer
Definition: stm32_spi.h:97
stm32_gpio_init_param::mode
uint32_t mode
Definition: stm32_gpio.h:46
DEV_TO_MEM
@ DEV_TO_MEM
Definition: no_os_dma.h:52
stm32_spi.h
Header file for the stm32 spi driver.
stm32_spi_desc::rxdma_ch
struct no_os_dma_ch * rxdma_ch
Definition: stm32_spi.h:88
no_os_gpio_init_param::port
int32_t port
Definition: no_os_gpio.h:81
stm32_spi_write_and_read
int32_t stm32_spi_write_and_read(struct no_os_spi_desc *desc, uint8_t *data, uint16_t bytes_number)
Write and read data to/from SPI.
Definition: stm32_spi.c:450
no_os_spi_init_param::mode
enum no_os_spi_mode mode
Definition: no_os_spi.h:148
NO_OS_GPIO_HIGH
@ NO_OS_GPIO_HIGH
Definition: no_os_gpio.h:117
no_os_gpio_init_param::number
int32_t number
Definition: no_os_gpio.h:83
stm32_gpio_init_param
Structure holding the initialization parameters for stm32 platform.
Definition: stm32_gpio.h:44
stm32_spi_init_param::txdma_ch
struct stm32_dma_channel * txdma_ch
Definition: stm32_spi.h:63
no_os_calloc
void * no_os_calloc(size_t nitems, size_t size)
Allocate memory and return a pointer to it, set memory to 0.
Definition: chibios_alloc.c:54
tx_pwm_init
struct no_os_pwm_init_param tx_pwm_init
Definition: parameters.c:134
stm32_spi_desc::stm32_spi_dma_user_cb
void(* stm32_spi_dma_user_cb)(void *ctx)
Definition: stm32_spi.h:94
stm32_spi_desc::hspi
SPI_HandleTypeDef hspi
Definition: stm32_spi.h:78
NO_OS_PULL_NONE
@ NO_OS_PULL_NONE
Definition: no_os_gpio.h:66
no_os_gpio_init_param::platform_ops
const struct no_os_gpio_platform_ops * platform_ops
Definition: no_os_gpio.h:87
stm32_dma_channel::hdma
DMA_HandleTypeDef * hdma
Definition: stm32_dma.h:66
stm32_spi_init_param::alternate
uint32_t alternate
Definition: stm32_spi.h:57
no_os_dma_config_xfer
int no_os_dma_config_xfer(struct no_os_dma_desc *, struct no_os_dma_xfer_desc *, uint32_t, struct no_os_dma_ch *)
Acquire a channel and configure the list of transfers.
Definition: no_os_dma.c:242
no_os_spi_msg::tx_buff
uint8_t * tx_buff
Definition: no_os_spi.h:102
no_os_spi_init_param::device_id
uint32_t device_id
Definition: no_os_spi.h:142
stm32_spi_init_param::rxdma_ch
struct stm32_dma_channel * rxdma_ch
Definition: stm32_spi.h:61
no_os_spi_init_param::chip_select
uint8_t chip_select
Definition: no_os_spi.h:146
no_os_mdelay
void no_os_mdelay(uint32_t msecs)
Wait until msecs milliseconds passed.
Definition: aducm3029_delay.c:126
no_os_spi_desc::chip_select
uint8_t chip_select
Definition: no_os_spi.h:200
stm32_spi_init_param::irq_num
uint32_t irq_num
Definition: stm32_spi.h:64
no_os_pwm_enable
int32_t no_os_pwm_enable(struct no_os_pwm_desc *desc)
Enable PWM signal generation.
Definition: no_os_pwm.c:98
stm32_spi_init
int32_t stm32_spi_init(struct no_os_spi_desc **desc, const struct no_os_spi_init_param *param)
Initialize the SPI communication peripheral.
Definition: stm32_spi.c:158
stm32_spi_desc::alternate
uint32_t alternate
Definition: stm32_spi.h:82
stm32_spi_desc::rx_ch_xfer
struct stm32_dma_channel * rx_ch_xfer
Definition: stm32_spi.h:96
no_os_dma_ch
Describes the state of a DMA channel.
Definition: no_os_dma.h:107
no_os_spi_msg::rx_buff
uint8_t * rx_buff
Definition: no_os_spi.h:104
stm32_spi_desc::txdma_ch
struct no_os_dma_ch * txdma_ch
Definition: stm32_spi.h:90
no_os_dma_xfer_desc::dst
uint8_t * dst
Definition: no_os_dma.h:75
no_os_pwm_disable
int32_t no_os_pwm_disable(struct no_os_pwm_desc *desc)
Disable PWM signal generation.
Definition: no_os_pwm.c:115
stm32_dma_channel
STM32 DMA Channels.
Definition: stm32_dma.h:64
stm32_spi_ops
const struct no_os_spi_platform_ops stm32_spi_ops
stm32 specific SPI platform ops structure
Definition: stm32_spi.c:698
stm32_spi_dma_callback
void stm32_spi_dma_callback(struct no_os_dma_xfer_desc *old_xfer, struct no_os_dma_xfer_desc *next_xfer, void *ctx)
Definition: stm32_spi.c:591
stm32_config_dma_and_start
int32_t stm32_config_dma_and_start(struct no_os_spi_desc *desc, struct no_os_spi_msg *msgs, uint32_t len, void(*callback)(struct no_os_dma_xfer_desc *old_xfer, struct no_os_dma_xfer_desc *next_xfer, void *ctx), void *ctx)
Configure and start a series of transfers using DMA.
Definition: stm32_spi.c:479
no_os_spi_desc::bit_order
enum no_os_spi_bit_order bit_order
Definition: no_os_spi.h:204
no_os_gpio_remove
int32_t no_os_gpio_remove(struct no_os_gpio_desc *desc)
Free the resources allocated by no_os_gpio_get().
Definition: no_os_gpio.c:104
no_os_spi_desc
Structure holding SPI descriptor.
Definition: no_os_spi.h:192
no_os_dma_xfer_desc
It's used to setup a generic DMA transfer.
Definition: no_os_dma.h:71
stm32_spi_init_param::dma_init
struct no_os_dma_init_param * dma_init
Definition: stm32_spi.h:59
no_os_dma_xfer_desc::xfer_complete_ctx
void * xfer_complete_ctx
Definition: no_os_dma.h:89
stm32_spi_remove
int32_t stm32_spi_remove(struct no_os_spi_desc *desc)
Free the resources allocated by no_os_spi_init().
Definition: stm32_spi.c:270
no_os_dma_xfer_desc::xfer_complete_cb
void(* xfer_complete_cb)(struct no_os_dma_xfer_desc *, struct no_os_dma_xfer_desc *, void *)
Definition: no_os_dma.h:82
no_os_gpio_desc
Structure holding the GPIO descriptor.
Definition: no_os_gpio.h:96
stm32_spi_init_param::chip_select_port
uint32_t chip_select_port
Definition: stm32_spi.h:53
no_os_dma_init
int no_os_dma_init(struct no_os_dma_desc **, struct no_os_dma_init_param *)
Initialize the DMA controller.
Definition: no_os_dma.c:90
no_os_dma_xfer_start
int no_os_dma_xfer_start(struct no_os_dma_desc *, struct no_os_dma_ch *)
Acquire a channel and configure the list of transfers.
Definition: no_os_dma.c:356
no_os_pwm_desc
Structure representing an PWM generator device.
Definition: no_os_pwm.h:93
no_os_spi_msg::bytes_number
uint32_t bytes_number
Definition: no_os_spi.h:106
no_os_spi_desc::extra
void * extra
Definition: no_os_spi.h:212
no_os_pwm_init
int32_t no_os_pwm_init(struct no_os_pwm_desc **desc, const struct no_os_pwm_init_param *param)
Initialize the PWM peripheral.
Definition: no_os_pwm.c:51
no_os_gpio_get
int32_t no_os_gpio_get(struct no_os_gpio_desc **desc, const struct no_os_gpio_init_param *param)
Obtain the GPIO decriptor.
Definition: no_os_gpio.c:49
stm32_spi_desc::stm32_spi_dma_user_ctx
void * stm32_spi_dma_user_ctx
Definition: stm32_spi.h:95
no_os_spi_init_param::max_speed_hz
uint32_t max_speed_hz
Definition: no_os_spi.h:144
no_os_pwm.h
Header file of PWM Interface.
stm32_gpio.h
Header file for stm32 gpio specifics.
no_os_dma_xfer_desc::xfer_type
enum no_os_dma_xfer_type xfer_type
Definition: no_os_dma.h:79
NO_OS_BIT
#define NO_OS_BIT(x)
Definition: no_os_util.h:45
no_os_free
void no_os_free(void *ptr)
Deallocate memory previously allocated by a call to no_os_calloc or no_os_malloc.
Definition: chibios_alloc.c:69
no_os_dma_remove
int no_os_dma_remove(struct no_os_dma_desc *)
Remove resources allocated for the DMA controller.
Definition: no_os_dma.c:143
stm32_spi_desc::dma_desc
struct no_os_dma_desc * dma_desc
Definition: stm32_spi.h:86
no_os_udelay
void no_os_udelay(uint32_t usecs)
Wait until usecs microseconds passed.
Definition: aducm3029_delay.c:114
NULL
#define NULL
Definition: wrapper.h:64
stm32_spi_ops
const struct no_os_spi_platform_ops stm32_spi_ops
stm32 platform specific SPI platform ops structure
Definition: stm32_spi.c:698
no_os_dma_xfer_desc::src
uint8_t * src
Definition: no_os_dma.h:73
no_os_dma_ch::extra
void * extra
Definition: no_os_dma.h:120
stm32_gpio_ops
const struct no_os_gpio_platform_ops stm32_gpio_ops
stm32 platform specific GPIO platform ops structure
Definition: stm32_gpio.c:389
no_os_dma_xfer_abort
int no_os_dma_xfer_abort(struct no_os_dma_desc *, struct no_os_dma_ch *)
Abort the ongoing and any other future transfers scheduled for a channel.
Definition: no_os_dma.c:384
stm32_gpio_init_param::speed
uint32_t speed
Definition: stm32_gpio.h:48
no_os_gpio_init_param::extra
void * extra
Definition: no_os_gpio.h:89
no_os_gpio.h
Header file of GPIO Interface.
MEM_TO_DEV
@ MEM_TO_DEV
Definition: no_os_dma.h:51
no_os_spi_desc::max_speed_hz
uint32_t max_speed_hz
Definition: no_os_spi.h:198
stm32_gpio_init_param::alternate
uint32_t alternate
Definition: stm32_gpio.h:50
stm32_spi_dma_transfer_async
int32_t stm32_spi_dma_transfer_async(struct no_os_spi_desc *desc, struct no_os_spi_msg *msgs, uint32_t len, void(*callback)(void *), void *ctx)
Configure and start a series of transfers using DMA. Don't Wait for the completion before returning.
Definition: stm32_spi.c:650
no_os_dma_desc::channels
struct no_os_dma_ch * channels
Definition: no_os_dma.h:142
no_os_util.h
Header file of utility functions.
NO_OS_SPI_CPHA
#define NO_OS_SPI_CPHA
Definition: no_os_spi.h:47
no_os_spi_platform_ops::init
int32_t(* init)(struct no_os_spi_desc **, const struct no_os_spi_init_param *)
Definition: no_os_spi.h:224
no_os_spi_init_param::extra
void * extra
Definition: no_os_spi.h:158
stm32_spi_desc::input_clock
uint32_t input_clock
Definition: stm32_spi.h:80
stm32_gpio_desc
stm32 platform specific gpio descriptor
Definition: stm32_gpio.h:57
no_os_spi_desc::mode
enum no_os_spi_mode mode
Definition: no_os_spi.h:202
stm32_spi_desc::chip_select
struct no_os_gpio_desc * chip_select
Definition: stm32_spi.h:84
no_os_gpio_direction_output
int32_t no_os_gpio_direction_output(struct no_os_gpio_desc *desc, uint8_t value)
Enable the output direction of the specified GPIO.
Definition: no_os_gpio.c:147
no_os_gpio_desc::number
int32_t number
Definition: no_os_gpio.h:100
stm32_hal.h
no_os_dma_xfer_desc::length
uint32_t length
Definition: no_os_dma.h:77
stm32_spi_desc::csip
struct no_os_gpio_init_param csip
Definition: stm32_spi.h:92
stm32_spi_init_param::get_input_clock
uint32_t(* get_input_clock)(void)
Definition: stm32_spi.h:55
stm32_spi_transfer
int32_t stm32_spi_transfer(struct no_os_spi_desc *desc, struct no_os_spi_msg *msgs, uint32_t len)
Write/read multiple messages to/from SPI.
Definition: stm32_spi.c:336
errno.h
Error macro definition for ARM Compiler.
NO_OS_DMA_IRQ
@ NO_OS_DMA_IRQ
Definition: no_os_irq.h:92
no_os_dma.h
Platform independent function definitions and data types for the DMA API.
stm32_spi_desc::csip_extra
struct stm32_gpio_init_param csip_extra
Definition: stm32_spi.h:91
stm32_pwm.h
Implementation of stm32 pwm driver.
no_os_spi_init_param
Structure holding the parameters for SPI initialization.
Definition: no_os_spi.h:140
no_os_dma_xfer_desc::periph
enum no_os_irq_peripheral periph
Definition: no_os_dma.h:97
no_os_dma_desc
Describes the state of the DMA controller.
Definition: no_os_dma.h:136