precision-converters-firmware
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 #if (INTERFACE_MODE != SPI_DMA_MODE)
26 #include "stm32_gpio_irq.h"
27 #else
28 #include "stm32_dma.h"
29 #endif
30 #include "stm32_tdm.h"
31 #if (INTERFACE_MODE == SPI_DMA_MODE)
32 #include "stm32_pwm.h"
33 #endif
34 
35 #if defined (TARGET_SDP_K1)
36 #include "stm32_usb_uart.h"
37 #endif
38 
39 /******************************************************************************/
40 /********************** Macros and Constants Definition ***********************/
41 /******************************************************************************/
42 
43 #if defined (TARGET_SDP_K1)
44 /* The below configurations are specific to STM32F469NIH6 MCU on SDP-K1 Board. */
45 #define HW_CARRIER_NAME SDP-K1
46 
47 /* STM32 SPI Specific parameters */
48 #define STM32_SPI_ID 1 // SPI1
49 #define STM32_SPI_CS_PORT 0 // GPIO Port A
50 #define SPI_CSB 15 // PA_15
51 
52 /* STM32 I2C Specific parameters */
53 #define STM32_I2C_ID 1 // I2C1
54 
55 /* STM32 UART specific parameters */
56 #define APP_UART_HANDLE &huart5
57 #define UART_IRQ_ID UART5_IRQn
58 
59 /* STM32 GPIO specific parameters */
60 #define DIG_AUX_1 7 // PG7
61 #define DIG_AUX_2 10 // PG10
62 #define SYNC_INB 9 // PG9
63 #define LED_GPO 4
64 
65 #define DIG_AUX_1_PORT 6 // GPIOG
66 #define DIG_AUX_2_PORT 6 // GPIOG
67 #define SYNC_INB_PORT 6 // GPIOG
68 #define SYNC_INB_PORT_ID GPIOG
69 
70 #define GPIO_TRIGGER_INT_PORT EXTI_GPIOG // PG7
71 
72 #define I2C_TIMING 0 // (Unused)
73 
74 /* SPI DMA specific parameters */
75 #define AD469x_DMA_NUM_CHANNELS 2
76 
77 #define Rx_DMA_IRQ_ID DMA2_Stream0_IRQn
78 #define AD469x_TxDMA_CHANNEL_NUM DMA_CHANNEL_7
79 #define AD469x_RxDMA_CHANNEL_NUM DMA_CHANNEL_3
80 
81 /* Tx Trigger timer parameters */
82 #define TX_TRIGGER_TIMER_ID 8 // Timer 8
83 /* Tx trigger period considering a MAX SPI clock of 22.5MHz and 32 bit transfer */
84 #define TX_TRIGGER_PERIOD 2250
85 #define TX_TRIGGER_DUTY_RATIO 240
86 #define TIMER_8_PRESCALER 0
87 #define TIMER_8_CLK_DIVIDER 1
88 #define TIMER_CHANNEL_1 1
89 #else
90 /* The below configurations are specific to STM32H563ZIT6 MCU on NUCLEO-H563ZI Board. */
91 #define HW_CARRIER_NAME NUCLEO-H563ZI
92 
93 /* STM32 SPI Specific parameters */
94 #define STM32_SPI_ID 1 // SPI1
95 #define STM32_SPI_CS_PORT 3 // GPIO Port D
96 #define SPI_CSB 14 // PD_14
97 
98 /* STM32 I2C Specific parameters */
99 #define STM32_I2C_ID 1 // I2C1
100 
101 /* STM32 UART specific parameters */
102 #define APP_UART_HANDLE &huart3
103 
104 /* STM32 GPIO specific parameters */
105 #define DIG_AUX_1 14 // PG14
106 #define DIG_AUX_2 12 // PG12
107 #define SYNC_INB 14 // PE14
108 #define LED_GPO LED1_GREEN_Pin
109 
110 #define DIG_AUX_1_PORT 6 // GPIOG
111 #define DIG_AUX_2_PORT 6 // GPIOG
112 #define SYNC_INB_PORT 4 // GPIOE
113 
114 #define GPIO_TRIGGER_INT_PORT EXTI_GPIOG // PG14
115 
116 /* I2C timing register value for standard mode of operation
117  * Check here for more understanding on I2C timing register
118  * configuration: https://wiki.analog.com/resources/no-os/drivers/i2c */
119 #define I2C_TIMING 0x00000E14
120 
121 /* TDM specific Parameters */
122 #define TDM_DATA_SIZE 32
123 #define TDM_SLOTS_PER_FRAME 1
124 #define TDM_FS_ACTIVE_LENGTH 8
125 
126 /* Expect DMA to read 800 samples in one cycle */
127 #define TDM_N_SAMPLES_DMA_READ 800
128 /* This makes sure that the processor gets into the
129  * Half complete callback function after every 400 samples */
130 #define TDM_DMA_READ_SIZE TDM_N_SAMPLES_DMA_READ * TDM_SLOTS_PER_FRAME/2
131 
132 #define STM32_SAI_BASE SAI1_Block_A
133 #endif
134 
135 /* Note: The below macro and the type of digital filter chosen together
136  * decides the output data rate to be configured for the device.
137  * Filter configuration can be modified by changing the macro "AD4170_FILTER_CONFIG"
138  * in the respective user configuration header file.
139  * Please refer to the datasheet for more details on the other filter configurations.
140  * It has to be noted that this is not the maximum ODR permissible by the device, but
141  * a value specific to the NUCLEO-H563ZI platform tested with a 10MHz SPI clock. The maximum
142  * ODR might vary across platforms and data continuity is not guaranteed above this ODR
143  * on the IIO Client*/
144 #if (INTERFACE_MODE == SPI_INTERRUPT_MODE)
145 #define FS_CONFIG_VALUE 20 // Value corresponding to 24KSPS ODR (per channel) with Sinc5 average filter
146 #elif (INTERFACE_MODE == SPI_DMA_MODE)
147 #define FS_CONFIG_VALUE 1 // Value correspoinding to 512ksps ODR (per channel) with Sinc5 filter
148 #else // TDM_MODE
149 #define FS_CONFIG_VALUE 1 // Value correspoinding to 512ksps ODR (per channel) with Sinc5 filter
150 #endif
151 
152 #define TICKER_INTERRUPT_PERIOD_uSEC (0) // unused
153 
154 /* Max SPI Speed */
155 #define AD4170_MAX_SPI_SPEED 20000000
156 
157 /******************************************************************************/
158 /********************** Public/Extern Declarations ****************************/
159 /******************************************************************************/
160 
161 extern struct stm32_spi_init_param stm32_spi_extra_init_params;
162 extern struct stm32_uart_init_param stm32_uart_extra_init_params;
163 extern struct stm32_gpio_init_param stm32_trigger_gpio_extra_init_params;
164 extern struct stm32_gpio_init_param stm32_dig_aux1_gpio_extra_init_params;
165 extern struct stm32_gpio_init_param stm32_dig_aux2_gpio_extra_init_params;
166 extern struct stm32_gpio_init_param stm32_sync_inb_gpio_extra_init_params;
167 extern struct stm32_gpio_init_param stm32_csb_gpio_extra_init_params;
168 extern struct stm32_gpio_irq_init_param stm32_trigger_gpio_irq_init_params;
169 extern struct stm32_tdm_init_param stm32_tdm_extra_init_params;
170 extern struct stm32_i2c_init_param stm32_i2c_extra_init_params;
171 #if !defined (TARGET_SDP_K1)
172 extern UART_HandleTypeDef huart3;
173 #else
174 extern UART_HandleTypeDef huart5;
175 extern DMA_HandleTypeDef hdma_spi1_rx;
176 extern DMA_HandleTypeDef hdma_tim8_ch1;
177 #endif
178 extern bool data_capture_operation;
179 extern struct iio_device_data *ad4170_iio_dev_data;
180 extern uint8_t num_of_active_channels;
181 extern volatile bool tdm_read_started;
182 extern volatile struct iio_device_data* iio_dev_data_g;
183 extern uint32_t nb_of_samples_g;
184 extern volatile uint32_t* buff_start_addr;
185 extern int32_t data_read;
186 extern uint32_t rxdma_ndtr;
187 extern volatile bool ad4170_dma_buff_full;
188 extern uint32_t dma_cycle_count;
189 extern struct stm32_spi_desc* sdesc;
190 
191 #if (INTERFACE_MODE == SPI_DMA_MODE)
192 extern struct stm32_pwm_init_param stm32_tx_trigger_extra_init_params;
193 extern struct no_os_dma_init_param ad4170_dma_init_param;
194 extern struct stm32_dma_channel rxdma_channel;
195 extern struct stm32_dma_channel txdma_channel;
196 #endif
197 #if defined (TARGET_SDP_K1)
198 extern USBD_HandleTypeDef hUsbDeviceHS;
199 extern struct stm32_usb_uart_init_param stm32_vcom_extra_init_params;
200 #endif
201 
202 void tim8_config(void);
203 void stm32_timer_stop(void);
204 void stm32_system_init(void);
205 void stm32_abort_dma_transfer(void);
206 void ad4170_dma_rx_cplt(SAI_HandleTypeDef *hsai);
207 void ad4170_dma_rx_half_cplt(SAI_HandleTypeDef *hsai);
208 void ad4170_spi_dma_rx_cplt_callback(DMA_HandleTypeDef* hdma);
209 void ad4170_spi_dma_rx_half_cplt_callback(DMA_HandleTypeDef* hdma);
210 void update_buff(uint32_t* local_buf, uint32_t* buf_start_addr);
211 void tim8_init(struct no_os_pwm_desc *pwm_desc);
213 #endif /* APP_CONFIG_STM32_H_ */
struct no_os_pwm_desc * pwm_desc
Definition: app_config.c:106
UART_HandleTypeDef huart5
struct stm32_gpio_irq_init_param stm32_trigger_gpio_irq_init_params
Definition: app_config_stm32.c:35
struct stm32_dma_channel txdma_channel
Definition: app_config_stm32.c:29
DMA_HandleTypeDef hdma_tim8_ch1
struct stm32_dma_channel rxdma_channel
Definition: app_config_stm32.c:39
uint32_t rxdma_ndtr
Definition: app_config_stm32.c:175
USBD_HandleTypeDef hUsbDeviceHS
void stm32_system_init(void)
Initialize the STM32 system peripherals.
Definition: app_config_stm32.c:111
int dma_cycle_count
Definition: app_config_stm32.c:169
struct stm32_pwm_init_param stm32_tx_trigger_extra_init_params
Definition: app_config_stm32.c:143
int stm32_abort_dma_transfer(void)
Abort ongoing SPI RX DMA transfer.
Definition: app_config_stm32.c:420
struct stm32_uart_init_param stm32_uart_extra_init_params
Definition: app_config_stm32.c:49
struct stm32_usb_uart_init_param stm32_vcom_extra_init_params
Definition: app_config_stm32.c:54
DMA_HandleTypeDef hdma_spi1_rx
void stm32_timer_stop(void)
Stops generating timer signals.
Definition: app_config_stm32.c:324
void update_buff(uint32_t *local_buf, uint32_t *buf_start_addr)
Update buffer index.
Definition: app_config_stm32.c:289
struct stm32_spi_init_param stm32_spi_extra_init_params
Definition: app_config_stm32.c:59
uint8_t local_buf[MAX_LOCAL_BUF_SIZE]
Definition: ad405x_iio.c:172
struct stm32_gpio_init_param stm32_csb_gpio_extra_init_params
Definition: app_config_stm32.c:93
struct stm32_gpio_init_param stm32_sync_inb_gpio_extra_init_params
Definition: app_config_stm32.c:73
volatile struct iio_device_data * iio_dev_data_g
Definition: ad405x_iio.c:322
uint32_t nb_of_samples_g
Definition: ad405x_iio.c:325
struct stm32_tdm_init_param stm32_tdm_extra_init_params
Definition: app_config_stm32.c:52
void ad4170_dma_rx_half_cplt(SAI_HandleTypeDef *hsai)
SAI DMA Receive Half Complete Callback function.
Definition: app_config_stm32.c:207
struct stm32_gpio_init_param stm32_dig_aux2_gpio_extra_init_params
Definition: app_config_stm32.c:67
volatile bool ad4170_dma_buff_full
struct stm32_i2c_init_param stm32_i2c_extra_init_params
Definition: app_config_stm32.c:99
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:303
struct iio_device_data * ad4170_iio_dev_data
Definition: ad4170_iio.c:319
struct stm32_spi_desc * sdesc
Definition: app_config_stm32.c:160
void tim8_config(void)
Configure Tx Trigger timer.
Definition: app_config_stm32.c:335
void tim8_init(struct no_os_pwm_desc *pwm_desc)
Initialize Tx trigger advanced PWM parameters.
Definition: app_config_stm32.c:397
uint8_t num_of_active_channels
Definition: ad4170_iio.c:183
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:266
bool data_capture_operation
Definition: ad4170_iio.c:337
volatile bool tdm_read_started
Definition: ad4170_iio.c:330
UART_HandleTypeDef huart3
struct stm32_gpio_init_param stm32_dig_aux1_gpio_extra_init_params
Definition: app_config_stm32.c:61
volatile uint32_t * buff_start_addr
Definition: ad405x_iio.c:169
int32_t data_read
Definition: ad405x_iio.c:328
struct stm32_gpio_init_param stm32_trigger_gpio_extra_init_params
Definition: app_config_stm32.c:55
void MX_USB_DEVICE_Init(void)
void ad4170_dma_rx_cplt(SAI_HandleTypeDef *hsai)
SAI DMA Receive Complete Callback function.
Definition: app_config_stm32.c:224
Configuration file of nanodac firmware example program.