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 "main.h"
20#include "stm32_spi.h"
21#include "stm32_i2c.h"
22#include "stm32_uart.h"
23#include "stm32_gpio.h"
24#include "app_config.h"
25#include "no_os_pwm.h"
26#if (INTERFACE_MODE == TDM_DMA_MODE)
27#include "stm32_tdm.h"
28#endif
29#include "stm32_gpio_irq.h"
30#if(INTERFACE_MODE == SPI_DMA_MODE)
31#include "stm32_dma.h"
32#endif
33#if (INTERFACE_MODE == SPI_DMA_MODE)
34#include "stm32_pwm.h"
35#endif
36#if defined (TARGET_SDP_K1)
37#include "stm32_usb_uart.h"
38#endif
39
40/******************************************************************************/
41/********************** Macros and Constants Definition ***********************/
42/******************************************************************************/
43
44#if defined (TARGET_SDP_K1)
45/* The below configurations are specific to STM32F469NIH6 MCU on SDP-K1 Board. */
46#define HW_CARRIER_NAME SDP_K1
47
48/* STM32 SPI Specific parameters */
49#define STM32_SPI_ID 1 // SPI1
50#define STM32_SPI_CS_PORT 0 // GPIO Port A
51#define SPI_CSB 15 // PA_15
52
53/* STM32 I2C Specific parameters */
54#define STM32_I2C_ID 1 // I2C1
55
56/* STM32 UART specific parameters */
57#define UART_DEVICE_ID 5
58#define APP_UART_HANDLE huart5
59#define UART_IRQ_ID UART5_IRQn
60
61/* STM32 GPIO specific parameters */
62#define DIG_AUX_1 7 // PG7
63#define DIG_AUX_2 10 // PG10
64#define SYNC_INB 9 // PG9
65#define LED_GPO 4
66
67#define DIG_AUX_1_PORT 6 // GPIOG
68#define DIG_AUX_2_PORT 6 // GPIOG
69#define SYNC_INB_PORT 6 // GPIOG
70#define SYNC_INB_PORT_ID GPIOG
71
72#define GPIO_TRIGGER_INT_PORT EXTI_GPIOG // PG7
73
74#define I2C_TIMING 0 // (Unused)
75
76/* SPI DMA specific parameters */
77#define AD469x_DMA_NUM_CHANNELS 2
78
79#define Rx_DMA_IRQ_ID DMA2_Stream0_IRQn
80#define AD469x_TxDMA_CHANNEL_NUM DMA_CHANNEL_7
81#define AD469x_RxDMA_CHANNEL_NUM DMA_CHANNEL_3
82
83/* Tx Trigger timer parameters */
84#define TX_TRIGGER_TIMER_ID 8 // Timer 8
85#define TX_TRIGGER_TIMER_HANDLE htim8
86/* Tx trigger period considering a MAX SPI clock of 20MHz and 32 bit transfer */
87#define TX_TRIGGER_PERIOD 700
88#define TX_TRIGGER_DUTY_RATIO 30
89#define TIMER_8_PRESCALER 0
90#define TIMER_8_CLK_DIVIDER 2
91#define TIMER_CHANNEL_1 1
92
93#elif defined (NUCLEO_H563)
94/* The below configurations are specific to STM32H563ZIT6 MCU on NUCLEO-H563ZI Board. */
95#define HW_CARRIER_NAME NUCLEO-H563ZI
96
97/* STM32 SPI Specific parameters */
98#define STM32_SPI_ID 1 // SPI1
99#define STM32_SPI_CS_PORT 3 // GPIO Port D
100#define SPI_CSB 14 // PD_14
101
102/* STM32 I2C Specific parameters */
103#define STM32_I2C_ID 1 // I2C1
104
105/* STM32 UART specific parameters */
106#define APP_UART_HANDLE huart3
107#define UART_IRQ_ID USART3_IRQn
108
109/* STM32 GPIO specific parameters */
110#define DIG_AUX_1 14 // PG14
111#define DIG_AUX_2 12 // PG12
112#define SYNC_INB 14 // PE14
113#define LED_GPO LED1_GREEN_Pin
114
115#define DIG_AUX_1_PORT 6 // GPIOG
116#define DIG_AUX_2_PORT 6 // GPIOG
117#define SYNC_INB_PORT 4 // GPIOE
118
119#define GPIO_TRIGGER_INT_PORT EXTI_GPIOG // PG14
120
121/* I2C timing register value for standard mode of operation
122 * Check here for more understanding on I2C timing register
123 * configuration: https://wiki.analog.com/resources/no-os/drivers/i2c */
124#define I2C_TIMING 0x00000E14
125
126/* TDM specific Parameters */
127#define TDM_DATA_SIZE 32
128#define TDM_SLOTS_PER_FRAME 1
129#define TDM_FS_ACTIVE_LENGTH 8
130
131/* Expect DMA to read 800 samples in one cycle */
132#define TDM_N_SAMPLES_DMA_READ 800
133/* This makes sure that the processor gets into the
134 * Half complete callback function after every 400 samples */
135#define TDM_DMA_READ_SIZE TDM_N_SAMPLES_DMA_READ * TDM_SLOTS_PER_FRAME/2
136
137#define STM32_SAI_BASE SAI1_Block_A
138#else
139/* The below configurations are specific to STM32F769NI MCU on Disco-F769NI Board. */
140#define HW_CARRIER_NAME DISCO-F769NI
141
142/* STM32 SPI Specific parameters */
143#define STM32_SPI_ID 2 // SPI1
144#define STM32_SPI_CS_PORT 0 // GPIO Port D
145#define SPI_CSB 11 // PA_11
146
147/* STM32 UART specific parameters */
148#define APP_UART_HANDLE huart6
149
150/* UART Device ID */
151#define UART_IRQ_ID USART6_IRQn
152
153#define STM32_I2C_ID 1 // I2C1
154
155/* I2C timing register value for standard mode of operation
156 * Check here for more understanding on I2C timing register
157 * configuration: TODO*/
158#define I2C_TIMING 0x40912732
159
160/* STM32 GPIO specific parameters */
161#define DIG_AUX_1 1 // PJ1
162#define DIG_AUX_2 3 // PI3
163#define SYNC_INB 0 // PJ0
164
165#define DIG_AUX_1_PORT 9 // GPIOJ
166#define DIG_AUX_2_PORT 8 // GPIOI
167#define SYNC_INB_PORT 9 // GPIOJ
168
169#define GPIO_TRIGGER_INT_PORT DIG_AUX_1_PORT
170
171/* Ticker for Pocket Lab */
172#define LVGL_TICK_TIME_US 5000
173#define LVGL_TICK_TIME_MS (LVGL_TICK_TIME_US / 1000)
174#endif
175
176/* Note: The below macro and the type of digital filter chosen together
177 * decides the output data rate to be configured for the device.
178 * Filter configuration can be modified by changing the macro "AD4170_FILTER_CONFIG"
179 * in the respective user configuration header file.
180 * Please refer to the datasheet for more details on the other filter configurations.
181 * It has to be noted that this is not the maximum ODR permissible by the device, but
182 * a value specific to the NUCLEO-H563ZI platform tested with a 10MHz SPI clock. The maximum
183 * ODR might vary across platforms and data continuity is not guaranteed above this ODR
184 * on the IIO Client*/
185
186/* Value corresponding to 24KSPS ODR (per channel) with Sinc5 average filter */
187#define FS_SINC5_AVG_24_KSPS 20
188
189/* Value corresponding to 512ksps ODR (per channel) with Sinc5 filter */
190#define FS_SINC5_512_KSPS 1
191
192/* Value corresponding to 62.5 ODR (per channel) with Sinc3 filter */
193#define FS_SINC3_62P5_KSPS 4
194
195#if (INTERFACE_MODE == SPI_INTERRUPT_MODE)
196#define FS_CONFIG_VALUE FS_SINC5_AVG_24_KSPS
197#define AD4170_MAX_SAMPLING_RATE 24000
198#else // TDM_MODE and SPI_DMA_MODE
199#if defined (DEV_AD4170)
200#define FS_CONFIG_VALUE FS_SINC5_512_KSPS
201#define AD4170_MAX_SAMPLING_RATE 500000
202#elif defined (DEV_AD4190)
203#define FS_CONFIG_VALUE FS_SINC3_62P5_KSPS
204#define AD4170_MAX_SAMPLING_RATE 62500
205#endif
206#endif
207
208/* Max SPI Speed */
209#define AD4170_MAX_SPI_SPEED 20000000
210
211/******************************************************************************/
212/********************** Public/Extern Declarations ****************************/
213/******************************************************************************/
214
215extern struct stm32_spi_init_param stm32_spi_extra_init_params;
216extern struct stm32_uart_init_param stm32_uart_extra_init_params;
217extern struct stm32_gpio_init_param stm32_trigger_gpio_extra_init_params;
218extern struct stm32_gpio_init_param stm32_dig_aux1_gpio_extra_init_params;
219extern struct stm32_gpio_init_param stm32_dig_aux2_gpio_extra_init_params;
220extern struct stm32_gpio_init_param stm32_sync_inb_gpio_extra_init_params;
221extern struct stm32_gpio_init_param stm32_csb_gpio_extra_init_params;
222extern struct stm32_gpio_irq_init_param stm32_trigger_gpio_irq_init_params;
223extern struct stm32_tdm_init_param stm32_tdm_extra_init_params;
224extern struct stm32_i2c_init_param stm32_i2c_extra_init_params;
225extern UART_HandleTypeDef APP_UART_HANDLE;
226extern uint8_t num_of_active_channels;
227
228#if defined (TARGET_SDP_K1)
229extern TIM_HandleTypeDef htim8;
230extern DMA_HandleTypeDef hdma_spi1_rx;
231extern DMA_HandleTypeDef hdma_tim8_ch1;
232extern USBD_HandleTypeDef hUsbDeviceHS;
234#endif
235#if defined(TARGET_SDP_K1) || defined(NUCLEO_H563)
236extern bool data_capture_operation;
237extern struct iio_device_data *ad4170_iio_dev_data;
238extern volatile bool tdm_read_started;
239extern volatile struct iio_device_data* iio_dev_data_g;
240extern uint32_t nb_of_samples_g;
241extern uint8_t* buff_start_addr;
242extern uint32_t data_read;
243extern uint32_t rxdma_ndtr;
244extern volatile bool ad4170_dma_buff_full;
245extern uint32_t dma_cycle_count;
246extern struct stm32_spi_desc* sdesc;
247
248#if (INTERFACE_MODE == SPI_DMA_MODE)
249extern struct stm32_pwm_init_param stm32_tx_trigger_extra_init_params;
250extern struct no_os_dma_init_param ad4170_dma_init_param;
251extern struct stm32_dma_channel rxdma_channel;
252extern struct stm32_dma_channel txdma_channel;
253#endif
254
255void tim8_config(void);
256void stm32_timer_stop(void);
257void stm32_abort_dma_transfer(void);
258void ad4170_dma_rx_cplt(SAI_HandleTypeDef *hsai);
259void ad4170_dma_rx_half_cplt(SAI_HandleTypeDef *hsai);
260void ad4170_spi_dma_rx_cplt_callback(DMA_HandleTypeDef* hdma);
261void ad4170_spi_dma_rx_half_cplt_callback(DMA_HandleTypeDef* hdma);
262void update_buff(uint8_t* local_buf, uint8_t* buf_start_addr);
263void tim8_init(struct no_os_pwm_desc *pwm_desc);
264void MX_USB_DEVICE_Init(void);
265extern volatile uint32_t callback_count;
266#endif
267
268void stm32_system_init(void);
269#endif /* APP_CONFIG_STM32_H_ */
struct no_os_pwm_desc * pwm_desc
Definition app_config.c:106
volatile struct stm32_spi_desc * sdesc
Definition app_config_stm32.c:147
int stm32_timer_stop(void)
Stop generating timer signals.
Definition app_config_stm32.c:284
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
void tim8_config(void)
Configure Tx Trigger timer for slave mode operation, one-pulse mode and to generate DMA requests.
Definition app_config_stm32.c:248
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
struct stm32_gpio_irq_init_param stm32_trigger_gpio_irq_init_params
Definition app_config_stm32.c:44
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_uart_init_param stm32_uart_extra_init_params
Definition app_config_stm32.c:102
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
#define APP_UART_HANDLE
Definition app_config_stm32.h:131
struct stm32_spi_init_param stm32_spi_extra_init_params
Definition app_config_stm32.c:43
struct stm32_gpio_init_param stm32_trigger_gpio_extra_init_params
Definition app_config_stm32.c:49
struct stm32_tdm_init_param stm32_tdm_extra_init_params
Definition app_config_stm32.c:55
bool data_capture_operation
Definition ad4134_iio.c:194
struct no_os_dma_init_param ad4170_dma_init_param
Definition app_config.c:153
struct stm32_dma_channel txdma_channel
Definition app_config_stm32.c:118
void ad4170_dma_rx_half_cplt(SAI_HandleTypeDef *hsai)
SAI DMA Receive Half Complete Callback function.
Definition app_config_stm32.c:229
volatile uint32_t callback_count
Definition app_config_stm32.c:38
void ad4170_spi_dma_rx_half_cplt_callback(DMA_HandleTypeDef *hdma)
Callback function to flag the capture of Half the number of requested samples.
Definition app_config_stm32.c:329
void tim8_init(struct no_os_pwm_desc *pwm_desc)
Initialize Tx trigger advanced PWM parameters.
Definition app_config_stm32.c:417
void ad4170_spi_dma_rx_cplt_callback(DMA_HandleTypeDef *hdma)
Callback function to flag the capture of number of requested samples.
Definition app_config_stm32.c:290
void ad4170_dma_rx_cplt(SAI_HandleTypeDef *hsai)
SAI DMA Receive Complete Callback function.
Definition app_config_stm32.c:248
struct stm32_gpio_init_param stm32_csb_gpio_extra_init_params
Definition app_config_stm32.c:99
struct stm32_gpio_init_param stm32_sync_inb_gpio_extra_init_params
Definition app_config_stm32.c:79
struct stm32_gpio_init_param stm32_dig_aux2_gpio_extra_init_params
Definition app_config_stm32.c:73
uint8_t num_of_active_channels
Definition ad4170_iio.c:197
struct stm32_gpio_init_param stm32_dig_aux1_gpio_extra_init_params
Definition app_config_stm32.c:67
uint32_t nb_of_samples_g
Definition ad4170_iio.c:401
volatile bool ad4170_dma_buff_full
Definition ad4170_iio.c:410
struct iio_device_data * ad4170_iio_dev_data
Definition ad4170_iio.c:335
volatile bool tdm_read_started
Definition ad4170_iio.c:346
TIM_HandleTypeDef htim8
void MX_USB_DEVICE_Init(void)
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