precision-converters-firmware
Loading...
Searching...
No Matches
app_config_stm32.h
Go to the documentation of this file.
1/***************************************************************************/
12#ifndef APP_CONFIG_STM32_H_
13#define APP_CONFIG_STM32_H_
14
15/******************************************************************************/
16/***************************** Include Files **********************************/
17/******************************************************************************/
18#include "main.h"
19#include "app_config.h"
20#include "stm32_uart.h"
21#include "stm32_spi.h"
22#include "stm32_pwm.h"
23#include "stm32_gpio.h"
24#include "stm32_i2c.h"
25#include "stm32_gpio_irq.h"
26#ifdef STM32F469xx
27#include "stm32_usb_uart.h"
28#include "stm32_uart_stdio.h"
29#include "usb_device.h"
30#elif defined STM32H563xx
31#include "stm32_tdm.h"
32#endif
33
34/******************************************************************************/
35/********************** Macros and Constants Definition ***********************/
36/******************************************************************************/
37#if defined(STM32H563xx)
38/* The below pin mapping is specific to STM32H563ZIT6 MCU on NUCLEO-H563ZI Board */
39#define STM32_SPI_ID 1 // SPI1
40#define SPI_CSB 14 // PD_14
41#define STM32_SPI_CS_PORT 3 // GPIO Port D
42
43#define DCLK_PIN 14 // PG14
44#define ODR_PIN 13 // PE13
45#define DOUT0_PIN 14 // PE14
46#define DOUT1_PIN 11 // PE11
47#define PDN_PIN 6 // PB6
48
49#define GPIO_TRIGGER_INT_PORT 4 // PORTE
50#define PDN_PORT 1 // PORTB
51
52/* STM32 specific UART parameters */
53#define STM32_UART_BASE 3
54
55/* STM32 specific SAI Parameters */
56#define STM32_SAI_BASE SAI1_Block_A
57
58#define APP_UART_HANDLE huart3
59
60/* TDM specific Parameters */
61#define TDM_DATA_SIZE 16
62#define TDM_SLOTS_PER_FRAME 4
63#define TDM_FS_ACTIVE_LENGTH 8
64
65/* This makes sure that the processor gets into the
66 * Half complete callback function after every 400 samples */
67#define TDM_N_SAMPLES_DMA_READ 800
68#define TDM_DMA_READ_SIZE TDM_N_SAMPLES_DMA_READ * TDM_SLOTS_PER_FRAME/2
69
70/* GPIO Pin Mask Values (Unused) */
71#define DCLK_PIN_MASK 0
72#define ODR_PIN_MASK 0
73#define DOUT0_PIN_MASK 0
74#define DOUT1_PIN_MASK 0
75
76#define DOUT1_IDR 0
77#define PORTD_IDR 0
78#define DCLK_IDR 0
79#define DOUT0_IDR 0
80
81#define UART_IRQ_ID USART3_IRQn
82#define UART_DEVICE_ID 0
83#define SPI_DEVICE_ID STM32_SPI_ID
84#define INTR_GPIO_TRIGGER_HANDLE 0 // Unused macro
85#define IRQ_INT_ID ODR_PIN
86#define DMA_IRQ_ID GPDMA1_Channel7_IRQn
87#define I2C_DEVICE_ID 1 // I2C1
88
89/* I2C timing register value for standard mode of operation
90 * Check here for more understanding on I2C timing register
91 * configuration: https://wiki.analog.com/resources/no-os/drivers/i2c */
92#define I2C_TIMING 0x00000E14
93
94/* Define the max possible sampling (or output data) rate for a given platform.
95 * Note: Max possible ODR is 500KSPS per channel for continuous data capture on
96 * IIO client. This is derived by testing the firmware on NUCLEO-H563ZI controller
97 * board. The max possible ODR can vary from board to board and data
98 * continuity is not guaranteed above this ODR on IIO oscilloscope */
99#define SAMPLING_RATE (500000)
100#else
101/* STM32 SPI specific parameters */
102#define STM32_SPI_ID 1 // SPI1
103#define SPI_CSB 15 // PA_15
104#define STM32_SPI_CS_PORT 0 // GPIO Port 0
105
106#define DCLK_PIN 7 //PG_7
107#define ODR_PIN 12 // PD_12
108#define DOUT0_PIN 9 //PG_9
109#define DOUT1_PIN 11 //PA_11
110#define PDN_PIN 0 //PA_0
111
112#define DCLK_PORT 6 //PG_7
113#define ODR_PORT 3 // PD_12
114#define DOUT0_PORT 6 //PG_9
115#define DOUT1_PORT 0 //PA_11
116#define PDN_PORT 0 //PA_0
117
118/* STM32 specific USB UART parameters */
119#define APP_UART_USB_HANDLE hUsbDeviceHS
120#define APP_UART_USB_IRQ OTG_HS_IRQn
121
122/* STM32 specific UART parameters */
123#define APP_UART_HANDLE huart5
124#define UART_IRQ_ID UART5_IRQn
125#define UART_DEVICE_ID 5
126
127#define SPI_DEVICE_ID STM32_SPI_ID
128#define IRQ_INT_ID ODR_PIN
129#define I2C_DEVICE_ID 1 // I2C1
130
131/* STM32 PWM Specific parameters */
132#define PWM_ID 4 // Timer4
133#define PWM_CHANNEL 1 // Channel 2
134#define PWM_CLK_DIVIDER 2 // multiplier to get timer clock from PCLK2
135#define PWM_PRESCALER 3
136#define PWM_HANDLE htim4
137
138#define GPIO_TRIGGER_INT_PORT ODR_PORT
139#define INTR_GPIO_TRIGGER_HANDLE 0 // Unused macro
140
141#define SAMPLING_RATE (12000)
142/* PWM period and duty cycle for AD7134 ASRC target mode. The low period of ODR as per specs
143 * must be minimum 3 * Tdclk in target mode. The min possible Fdclk for SDP-K1 (STM32F469NI)
144 * platform is ~3Mhz (based on time to sample data over DOUT), which gives Tdclk as ~333nsec.
145 * So ODR min low time must be 333ns * 3 = ~1usec. This is achieved by dividing total ODR
146 * period by 40 as below for 16KSPS ODR */
147#define CONV_TRIGGER_PERIOD_NSEC (((float)(1.0 / SAMPLING_RATE) * 1000000) * 1000)
148#define CONV_TRIGGER_DUTY_CYCLE_NSEC (CONV_TRIGGER_PERIOD_NSEC / 40)
149
150/* Memory map for GPIOs on SDP-K1/STM32F4xxx MCU to read the values.
151 * STM32 for SDP-K1 GPIO read/write library functions are very time stringent.
152 * Since data capture on AD7134 is done using bit banging method, memory mapped
153 * IOs are used for faster access of IO pins.
154 * IF USING ANY OTHER BOARD MAKE SURE MEMORY MAP IS UPDATED ACCORDINGLY */
155
156/* Memory address of PORTx IDR (input data) register (Base + 0x10 offset) */
157#define DOUT1_IDR (*((volatile uint32_t *)0x40020010)) // PORTA IDR
158#define ODR_IDR (*((volatile uint32_t *)0x40020C10)) // PORTD_IDR
159#define DCLK_IDR (*((volatile uint32_t *)0x40021810)) // PORTG IDR
160#define DOUT0_IDR (*((volatile uint32_t *)0x40021810)) // PORTG IDR
161#define DCLK_ODR (*((volatile uint32_t *)0x40021814)) // PORTG ODR
162
163/* Pin mask values for GPIOs */
164#define DCLK_PIN_MASK (uint32_t)(1 << DCLK_PIN)
165#define ODR_PIN_MASK (uint32_t)(1 << ODR_PIN)
166#define DOUT0_PIN_MASK (uint32_t)(1 << DOUT0_PIN)
167#define DOUT1_PIN_MASK (uint32_t)(1 << DOUT1_PIN)
168
169/* I2C timing register value for standard mode of operation
170 * Check here for more understanding on I2C timing register
171 * configuration: https://wiki.analog.com/resources/no-os/drivers/i2c */
172#define I2C_TIMING 0x00000E14
173#endif
174
175/******************************************************************************/
176/********************** Public/Extern Declarations ****************************/
177/******************************************************************************/
178extern struct stm32_uart_init_param stm32_uart_extra_init_params;
179extern struct stm32_spi_init_param stm32_spi_extra_init_params;
180extern struct stm32_tdm_init_param stm32_tdm_extra_init_params;
181extern struct stm32_gpio_irq_init_param stm32_trigger_gpio_irq_init_params;
182extern struct stm32_gpio_init_param stm32_pdn_extra_init_params;
183extern struct stm32_i2c_init_param stm32_i2c_extra_init_params;
184extern struct stm32_pwm_init_param stm32_pwm_extra_init_params;
185extern struct stm32_gpio_init_param stm32_pwm_gpio_init_params;
187extern struct stm32_gpio_init_param stm32_input_extra_init_params;
188extern struct stm32_gpio_init_param stm32_output_extra_init_params;
189extern UART_HandleTypeDef APP_UART_HANDLE;
190#ifdef STM32F469xx
191extern TIM_HandleTypeDef htim4;
192extern USBD_HandleTypeDef APP_UART_USB_HANDLE;
193#endif
194#if (INTERFACE_MODE == TDM_MODE)
195extern bool data_capture_operation;
196extern struct iio_device_data *ad7134_iio_dev_data;
197void ad7134_dma_rx_cplt(void *hsai);
198void ad7134_dma_rx_half_cplt(void *hsai);
199#endif
200
201void stm32_system_init(void);
202
203#endif /* APP_CONFIG_STM32_H_ */
204
void stm32_system_init(void)
Initialize the STM32 system peripherals.
Definition app_config_stm32.c:176
struct stm32_usb_uart_init_param stm32_vcom_extra_init_params
Definition app_config_stm32.c:38
#define APP_UART_USB_HANDLE
Definition app_config_stm32.h:44
struct stm32_gpio_irq_init_param stm32_trigger_gpio_irq_init_params
Definition app_config_stm32.c:43
TIM_HandleTypeDef htim4
struct stm32_i2c_init_param stm32_i2c_extra_init_params
Definition app_config_stm32.c:152
struct stm32_uart_init_param stm32_uart_extra_init_params
Definition app_config_stm32.c:102
#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_tdm_init_param stm32_tdm_extra_init_params
Definition app_config_stm32.c:55
struct stm32_gpio_init_param stm32_input_extra_init_params
Definition app_config_stm32.c:94
struct stm32_gpio_init_param stm32_output_extra_init_params
Definition app_config_stm32.c:100
void ad7134_dma_rx_cplt(void *hsai)
SAI DMA Receive Complete Callback function.
Definition app_config_stm32.c:183
struct stm32_gpio_init_param stm32_pwm_gpio_init_params
Definition app_config_stm32.c:88
bool data_capture_operation
Definition ad4134_iio.c:194
struct stm32_pwm_init_param stm32_pwm_extra_init_params
Definition app_config_stm32.c:77
struct iio_device_data * ad7134_iio_dev_data
Definition ad4134_iio.c:187
struct stm32_gpio_init_param stm32_pdn_extra_init_params
Definition app_config_stm32.c:66
void ad7134_dma_rx_half_cplt(void *hsai)
SAI DMA Receive Half Complete Callback function.
Definition app_config_stm32.c:168
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