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