precision-converters-firmware
Loading...
Searching...
No Matches
app_config_stm32.h
Go to the documentation of this file.
1/***************************************************************************/
13#ifndef APP_CONFIG_STM32_H_
14#define APP_CONFIG_STM32_H_
15
16/******************************************************************************/
17/***************************** Include Files **********************************/
18/******************************************************************************/
19#include <stdint.h>
20
21#include "stm32_hal.h"
22#include "stm32_i2c.h"
23#include "stm32_irq.h"
24#include "stm32_gpio_irq.h"
25#include "stm32_spi.h"
26#include "stm32_gpio.h"
27#include "stm32_uart.h"
28#include "stm32_pwm.h"
29#include "stm32_pwm_ex.h"
30#include "stm32_dma.h"
31#include "stm32_usb_uart.h"
32#include "ad4692_iio.h"
33#include "app_config.h"
34
35/******************************************************************************/
36/********************** Macros and Constants Definition ***********************/
37/******************************************************************************/
38/* Note: The SDP-K1 board with the STM32F469NI MCU has been used
39* for developing the firmware. The below parameters will change depending
40* on the controller used. */
41#define HW_CARRIER_NAME SDP_K1
42
43/* Pin mapping w.r.t Arduino Headers */
44#define I2C_DEV_ID 1 // I2C1
45#define UART_MODULE 5 // UART5
46#if defined (USE_PHY_COM_PORT)
47#define UART_IRQ UART5_IRQn
48#else
49#define UART_IRQ OTG_HS_IRQn
50#define CONSOLE_IRQ UART5_IRQn
51#endif
52#define SPI_DEVICE_ID 1 // SPI1
53#define SPI_CSB 15 // PA_15
54#define SPI_CS_PORT_BASE GPIOA
55#define SPI_CS_PORT_NUM 0 // PORTA = 0
56#define CNV_PIN_NUM 10 // PA_10
57#define CNV_PORT_NUM 0 // PORTA = 0
58#define CNV_PORT_BASE GPIOA
59#define BSY_PIN_NUM 0 // PA_0
60#define BSY_PORT_NUM 0 // PORTA = 0
61#define RESET_PIN_NUM 9 // PG_9
62#define RESET_PORT_NUM 6 // PORTG = 6
63#define TRIGGER_INT_ID BSY_PIN_NUM
64#define TRIGGER_GPIO_PORT 0 // Unused macro
65#define TRIGGER_GPIO_PIN GP0_PIN_NUM
66#define MAX_SPI_BAUDRATE 22500000
67
68/* Dummy PWM for triggering SPI Burst data capture */
69#define SPI_BURST_PWM_ID 12 // PD_12
70#define SPI_BURST_PWM_PORT 3 // PORTD
71
72#define gpio_ops stm32_gpio_ops
73#define spi_ops stm32_spi_ops
74#define i2c_ops stm32_i2c_ops
75#define vcom_ops stm32_usb_uart_ops
76#define uart_ops stm32_uart_ops
77#define pwm_ops stm32_pwm_ops
78#define dma_ops stm32_dma_ops
79#define trigger_gpio_irq_ops stm32_gpio_irq_ops
80#define trigger_gpio_handle 0 // Unused macro
81#define vcom_extra_init_params stm32_vcom_extra_init_params
82#define uart_extra_init_params stm32_uart_extra_init_params
83#define spi_extra_init_params stm32_spi_extra_init_params
84#define gpio_input_extra_init_params stm32_gpio_input_extra_init_params
85#define gpio_output_extra_init_params stm32_gpio_output_extra_init_params
86#define pwm_cnv_extra_init_params stm32_pwm_cnv_extra_init_params
87#define pwm_spi_burst_extra_init_params stm32_pwm_spi_burst_extra_init_params
88#define trigger_gpio_irq_extra_params stm32_gpio_irq_extra_init_params
89#define cnv_pwm_gpio_extra_init_params stm32_cnv_pwm_gpio_extra_init_params
90#define tx_trigger_extra_init_params stm32_tx_trigger_extra_init_params
91#define i2c_extra_init_params stm32_i2c_extra_init_params
92#define spi_burst_extra_init_params stm32_spi_burst_pwm_gpio_extra_init_params
93
94/* Timer specific macros used for calculating pwm
95 * period and duty cycle */
96#define CNV_TIMER_ID 1 // Timer 1
97#define TIMER_1_PRESCALER 1
98#define TIMER_1_CLK_DIVIDER 2
99#define CNV_TIMER_HANDLE htim1
100
101/* SPI Burst Timer specific parameters */
102#define SPI_BURST_TIMER_ID 4 //TIM4
103#define TIMER_4_PRESCALER 1
104#define TIMER_4_CLK_DIVIDER 1
105#define SPI_BURST_TIMER_HANDLE htim4
106
107/* Timer Channels */
108#define TIMER_CHANNEL_3 3
109
110/* Tx Trigger timer parameters */
111#define TX_TRIGGER_TIMER_ID 8 // Timer 8
112#define TX_TRIGGER_PERIOD 400
113#define TX_TRIGGER_DUTY_RATIO 30
114#define TX_TRIGGER_PRESCALER 0
115#define TX_TRIGGER_CLK_DIVIDER 2
116#define TIMER_CHANNEL_1 1
117#define TX_TRIGGER_TIMER_HANDLE htim8
118
119#define AD4692_DMA_NUM_CHANNELS 2
120#define Rx_DMA_IRQ_ID DMA2_Stream0_IRQn
121#define AD4692_TxDMA_CHANNEL_NUM DMA_CHANNEL_7
122#define AD4692_RxDMA_CHANNEL_NUM DMA_CHANNEL_3
123
124#define I2C_TIMING 0
125
126/* Priority for the GPIO interrupt */
127#define GPIO_IRQ_PRIORITY 1
128
129/* Maximum sampling rate for each ADC Mode. These values are arrived at, based on
130 * empirical measurements done with the logic analyzer using the worst-case settings.
131 * This is derived by testing the firmware on STM32F469NI MCU @22Mhz SPI clock.
132 * The max possible ODR can vary from board to board and data continuity is not guaranteed
133 * above this ODR on IIO oscilloscope */
134#define S_RATE_MANUAL_DMA (800000)
135#define S_RATE_MANUAL_INTR (50000)
136
137/* Sampling rate for Standard Sequencer in Averaged Data Readback Mode */
138#define S_RATE_CNV_CLOCK_INTR_STD_AVG (6250)
139#define S_RATE_CNV_BURST_STD_AVG (5750)
140#define S_RATE_SPI_BURST_STD_AVG (5750)
141
142/* Sampling rate for Standard Sequencer in Accumulator Data Readback Mode */
143#define S_RATE_CNV_CLOCK_INTR_STD_ACC (5500)
144#define S_RATE_CNV_BURST_STD_ACC (5000)
145#define S_RATE_SPI_BURST_STD_ACC (5000)
146
147/* Sampling rate for Advanced Sequencer in Average Data Readback Mode */
148#define S_RATE_CNV_CLOCK_INTR_ADV_AVG (6250)
149#define S_RATE_CNV_BURST_ADV_AVG (4500)
150#define S_RATE_SPI_BURST_ADV_AVG (4500)
151
152/* Sampling rate for Advanced Sequencer in Accumulator Data Readback Mode */
153#define S_RATE_CNV_CLOCK_INTR_ADV_ACC (5500)
154#define S_RATE_CNV_BURST_ADV_ACC (4000)
155#define S_RATE_SPI_BURST_ADV_ACC (4000)
156
157/******************************************************************************/
158/********************** Public/Extern Declarations ****************************/
159/******************************************************************************/
160
161extern DMA_HandleTypeDef hdma_spi1_rx;
162extern DMA_HandleTypeDef hdma_tim8_ch1;
163extern TIM_HandleTypeDef htim1;
164extern TIM_HandleTypeDef htim8;
165extern TIM_HandleTypeDef htim4;
166
167extern struct stm32_uart_init_param stm32_uart_extra_init_params;
168extern struct stm32_spi_init_param stm32_spi_extra_init_params;
169extern struct stm32_gpio_init_param stm32_gpio_output_extra_init_params;
170extern struct stm32_gpio_init_param stm32_gpio_input_extra_init_params;
171extern struct stm32_gpio_irq_init_param stm32_gpio_irq_extra_init_params;
172extern struct stm32_pwm_init_param stm32_pwm_cnv_extra_init_params;
173extern struct stm32_gpio_init_param stm32_cnv_pwm_gpio_extra_init_params;
174extern struct stm32_pwm_init_param stm32_tx_trigger_extra_init_params;
175extern struct stm32_i2c_init_param stm32_i2c_extra_init_params;
176extern struct no_os_dma_init_param ad4692_dma_init_param;
177extern struct stm32_dma_channel rxdma_channel;
178extern struct stm32_dma_channel txdma_channel;
179extern struct stm32_pwm_init_param stm32_pwm_spi_burst_extra_init_params;
180extern struct stm32_gpio_init_param stm32_spi_burst_pwm_gpio_extra_init_params;
181extern struct iio_device_data *ad4692_iio_dev_data;
182extern uint8_t num_of_active_channels;
183extern volatile struct iio_device_data* iio_dev_data_g;
184extern uint32_t nb_of_samples_g;
185extern volatile uint32_t* buff_start_addr;
186extern uint32_t data_read;
187extern uint32_t rxdma_ndtr;
188extern volatile bool ad4692_dma_buff_full;
189extern uint32_t dma_cycle_count;
190extern struct no_os_gpio_desc* csb_gpio_desc;
191extern uint32_t callback_count;
192extern USBD_HandleTypeDef hUsbDeviceHS;
195extern UART_HandleTypeDef huart5;
196
197void stm32_system_init(void);
198int ad4692_config_and_start_pwm(struct ad4692_desc *desc);
199void ad4692_stop_timer(void);
200void ad4692_spi_dma_rx_cplt_callback(DMA_HandleTypeDef* hdma);
201void ad4692_spi_dma_rx_half_cplt_callback(DMA_HandleTypeDef* hdma);
202void stm32_abort_dma_transfer(void);
203void update_buff(uint8_t *local_buf, uint8_t *buf_start_addr);
205int32_t tx_trigger_init(void);
206void stm32_tim4_init(void);
207
208#endif /* APP_CONFIG_STM32_H_ */
UART_HandleTypeDef huart5
DMA_HandleTypeDef hdma_tim8_ch1
struct stm32_dma_channel rxdma_channel
Definition app_config_stm32.c:137
USBD_HandleTypeDef hUsbDeviceHS
void stm32_system_init(void)
Initialize the STM32 system peripherals.
Definition app_config_stm32.c:178
struct stm32_pwm_init_param stm32_tx_trigger_extra_init_params
Definition app_config_stm32.c:100
int stm32_abort_dma_transfer(void)
Abort DMA Transfers.
Definition app_config_stm32.c:318
struct stm32_usb_uart_init_param stm32_vcom_extra_init_params
Definition app_config_stm32.c:39
DMA_HandleTypeDef hdma_spi1_rx
TIM_HandleTypeDef htim4
uint32_t data_read
Definition app_support.c:49
struct stm32_i2c_init_param stm32_i2c_extra_init_params
Definition app_config_stm32.c:166
volatile int dma_cycle_count
Definition app_config_stm32.c:242
uint32_t rxdma_ndtr
Definition app_config_stm32.c:245
void update_buff(uint8_t *local_buf, uint8_t *buf_start_addr)
Update buffer index.
Definition app_config_stm32.c:499
struct stm32_pwm_init_param stm32_pwm_cnv_extra_init_params
Definition app_config_stm32.c:190
struct stm32_uart_init_param stm32_uart_extra_init_params
Definition app_config_stm32.c:102
struct stm32_gpio_irq_init_param stm32_gpio_irq_extra_init_params
Definition app_config_stm32.c:156
volatile struct iio_device_data * iio_dev_data_g
Definition ad405x_iio.c:281
volatile uint8_t * buff_start_addr
Definition ad405x_iio.c:140
uint8_t local_buf[MAX_LOCAL_BUF_SIZE]
Definition ad405x_support.c:42
struct stm32_spi_init_param stm32_spi_extra_init_params
Definition app_config_stm32.c:43
struct stm32_dma_channel txdma_channel
Definition app_config_stm32.c:118
volatile uint32_t callback_count
Definition app_config_stm32.c:38
uint8_t num_of_active_channels
Definition ad4170_iio.c:195
uint32_t nb_of_samples_g
Definition ad4170_iio.c:397
void ad4692_spi_dma_rx_cplt_callback(DMA_HandleTypeDef *hdma)
Callback function to flag the capture of number of requested samples.
Definition app_config_stm32.c:309
TIM_HandleTypeDef htim1
int ad4692_config_and_start_pwm(struct ad4692_desc *desc)
Configure and start PWM.
Definition app_config_stm32.c:207
void ad4692_stop_timer(void)
Stop timers and DMA transfers.
Definition app_config_stm32.c:238
void ad4692_spi_dma_rx_half_cplt_callback(DMA_HandleTypeDef *hdma)
Callback function to flag the capture of number of requested samples.
Definition app_config_stm32.c:291
struct stm32_gpio_init_param stm32_gpio_output_extra_init_params
Definition app_config_stm32.c:43
void stm32_tim4_init(void)
Initialize Timer 4.
Definition app_config_stm32.c:382
int32_t tx_trigger_init(void)
Initialize Tx Trigger Timer.
Definition app_config.c:421
TIM_HandleTypeDef htim8
struct stm32_gpio_init_param stm32_gpio_input_extra_init_params
Definition app_config_stm32.c:49
struct iio_device_data * ad4692_iio_dev_data
void SystemClock_Config(void)
struct stm32_gpio_init_param stm32_cnv_pwm_gpio_extra_init_params
Definition app_config_stm32.c:91
struct stm32_gpio_init_param stm32_spi_burst_pwm_gpio_extra_init_params
Definition app_config_stm32.c:72
struct no_os_dma_init_param ad4692_dma_init_param
Definition app_config.c:156
struct no_os_gpio_desc * csb_gpio_desc
Definition app_config.c:175
struct stm32_pwm_init_param stm32_pwm_spi_burst_extra_init_params
Definition app_config_stm32.c:60
volatile bool ad4692_dma_buff_full
Definition ad4692_iio.c:404
void MX_USB_DEVICE_Init(void)
Header file of ad4692_iio.
Configuration file of nanodac firmware example program.
Extended support for STM32 PWM peripheral.
VCOM driver for stm32 as a no_os_uart implementation.
Specific initialization parameters for stm32 UART over USB.
Definition stm32_usb_uart.h:27