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