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
20#include "app_config.h"
21#include "stm32_uart.h"
22#include "stm32_spi.h"
23#include "stm32_tdm.h"
24#include "stm32_gpio.h"
25#include "stm32_i2c.h"
26#include "stm32_gpio_irq.h"
27#include "stm32_pwm.h"
28
29/******************************************************************************/
30/********************** Macros and Constants Definition ***********************/
31/******************************************************************************/
32
33/* Note: The NUCLEO-H563ZI board with the STM32H563ZIT6 MCU has been used
34 * for developing the firmware. The below parameters will change depending
35 * on the controller used. */
36
37/* STM32 SPI Macro definitions */
38#define STM32_SPI_ID 1 // SPI1
39#define STM32_SPI_CS_PORT 3 // GPIO Port D
40#define SPI_CSB 14 // GPIO Pin 14
41
42/* GPIO Pins for the Pin control mode in AD777x */
43#define GPIO_RESET_PIN 14 // PG14
44#define GPIO_MODE0_PIN 0 // Unused
45#define GPIO_MODE1_PIN 0 // Unused
46#define GPIO_MODE2_PIN 0 // Unused
47#define GPIO_MODE3_PIN 0 // Unused
48
49#define GPIO_DCLK0_PIN 0 // Unused
50#define GPIO_DCLK1_PIN 0 // Unused
51#define GPIO_DCLK2_PIN 0 // Unused
52#define GPIO_SYNC_IN_PIN 7 // PB7
53#define GPIO_CONVST_SAR_PIN 6 // PB6
54#define GPIO_DRDY_PIN 3 // PF3
55#define GPIO_ERROR_LED LED3_RED_Pin
56
57/* Port names */
58#define GPIO_RESET_PORT 6 // GPIOG
59#define GPIO_MODE0_PORT 0 // Unused
60#define GPIO_MODE1_PORT 0 // Unused
61#define GPIO_MODE2_PORT 0 // Unused
62#define GPIO_MODE3_PORT 0 // Unused
63#define GPIO_DCLK0_PORT 0 // Unused
64#define GPIO_DCLK1_PORT 0 // Unused
65#define GPIO_DCLK2_PORT 0 // Unused
66#define GPIO_SYNC_PORT 1 // GPIOB
67#define GPIO_CONVST_PORT 3 // GPIOD
68#define GPIO_DRDY_PORT 5 // GPIOF
69#define GPIO_ERROR_LED_PORT 0 // GPIOA
70
71#define GPIO_TRIGGER_INT_PORT EXTI_GPIOF
72
73#define APP_UART_HANDLE &huart3
74#define SAI_BASE SAI1_Block_A
75
76#define IRQ_INT_ID GPIO_DRDY_PIN
77#define UART_IRQ_ID USART3_IRQn
78#define DMA_IRQ_ID GPDMA1_Channel7_IRQn
79#define DRDY_IRQ_CTRL_ID GPIO_DRDY_PIN
80#define UART_DEVICE_ID 0
81#define SPI_DEVICE_ID STM32_SPI_ID
82#define I2C_DEVICE_ID 1 // I2C1
83#define MCLK_PWM_ID 1 // Timer 1
84#define TIMER1_ID 1
85#define MCLK_PWM_PRESCALER 1
86#define MCLK_PWM_CHANNEL 3 // Channel 3
87#define MCLK_PWM_CLK_DIVIDER 2
88#define MCLK_PWM_HANDLE htim1
89
90/* I2C timing register value for standard mode of operation
91 * Check here for more understanding on I2C timing register
92 * configuration: https://wiki.analog.com/resources/no-os/drivers/i2c */
93#define I2C_TIMING 0x00000E14
94
95/* pre-empt and sub priority for the peripherals except UART */
96#define PERIPH_INTR_PRE_EMPT_PRIORITY 7
97#define PERIPH_INTR_SUB_PRI_PRIORITY 3
98
99/* pre-empt and sub priority for UART peripheral */
100#define UART_PRE_EMPT_PRIORITY 2
101#define UART_SUB_PRI_PRIORITY 0
102
103/* SAI-TDM configurations for 32 bit channel data and 8 channels */
104#define TDM_DATA_SIZE 32
105#define TDM_SLOTS_PER_FRAME 8
106#define TDM_FS_ACTIVE_LENGTH 1
107
108/* This makes sure that the processor gets into the
109 * Half complete callback function after every 400 samples */
110#define TDM_N_SAMPLES_DMA_READ 800
111#define TDM_DMA_READ_SIZE TDM_N_SAMPLES_DMA_READ * TDM_SLOTS_PER_FRAME/2
112
113/* Define the Sampling Frequency. It needs to be noted that the
114 * maximum sampling frequency attainable in SPI Mode is
115 * only 8ksps (which is not the maximum ODR permissible by the device),
116 * Beyond with continuous data capturing cannot be guaranteed.
117 * This restriction is due to the time taken
118 * by the SPI drivers to read the data of all the 8 channels
119 * available on the SPI line. Occurrence of successive interrupts
120 * during the SPI read time posts a restriction on the maximum
121 * achievable ODR on the software
122 * The maximum permissible device ODR can be achieved via TDM Mode. */
123#if (INTERFACE_MODE == TDM_MODE)
124#if defined (DEV_AD7770)
125#define AD777x_SAMPLING_FREQUENCY 32000
126#elif defined (DEV_AD7771)
127#define AD777x_SAMPLING_FREQUENCY 128000
128#else
129#define AD777x_SAMPLING_FREQUENCY 16000
130#endif
131#else
132#define AD777x_SAMPLING_FREQUENCY 8000
133#endif
134
135/******************************************************************************/
136/********************** Public/Extern Declarations ****************************/
137/******************************************************************************/
138
139extern struct stm32_uart_init_param stm32_uart_extra_init_params;
140extern struct stm32_spi_init_param stm32_spi_extra_init_params;
141extern struct stm32_gpio_init_param stm32_gpio_reset_extra_init_params;
142extern struct stm32_gpio_init_param stm32_gpio_mode0_extra_init_params;
143extern struct stm32_gpio_init_param stm32_gpio_mode1_extra_init_params;
144extern struct stm32_gpio_init_param stm32_gpio_mode2_extra_init_params;
145extern struct stm32_gpio_init_param stm32_gpio_mode3_extra_init_params;
146extern struct stm32_gpio_init_param stm32_gpio_dclk0_extra_init_params;
147extern struct stm32_gpio_init_param stm32_gpio_dclk1_extra_init_params;
148extern struct stm32_gpio_init_param stm32_gpio_dclk2_extra_init_params;
149extern struct stm32_gpio_init_param stm32_gpio_sync_in_extra_init_params;
150extern struct stm32_gpio_init_param stm32_gpio_convst_sar_extra_init_params;
151extern struct stm32_gpio_init_param stm32_gpio_drdy_extra_init_params;
152extern struct stm32_gpio_init_param stm32_gpio_error_extra_init_params;
153extern struct stm32_gpio_irq_init_param stm32_trigger_gpio_irq_init_params;
154extern struct stm32_tdm_init_param stm32_tdm_extra_init_params;
155extern struct stm32_pwm_init_param stm32_pwm_extra_init_params;
156extern struct stm32_i2c_init_param stm32_i2c_extra_init_params;
157extern UART_HandleTypeDef huart3;
158extern TIM_HandleTypeDef htim1;
159extern bool data_capture_operation;
160extern struct iio_device_data *ad777x_iio_dev_data;
162HAL_StatusTypeDef HAL_Init(void);
164void MX_SPI1_Init(void);
165void MX_ICACHE_Init(void);
166void MX_GPIO_Init(void);
168void ad777x_dma_rx_cplt(SAI_HandleTypeDef *hsai);
169void ad777x_dma_rx_half_cplt(SAI_HandleTypeDef *hsai);
170
171#endif /* APP_CONFIG_STM32_H_ */
struct stm32_gpio_irq_init_param stm32_trigger_gpio_irq_init_params
Definition app_config_stm32.c:43
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
struct stm32_spi_init_param stm32_spi_extra_init_params
Definition app_config_stm32.c:46
void MX_ICACHE_Init(void)
struct stm32_tdm_init_param stm32_tdm_extra_init_params
Definition app_config_stm32.c:52
void MX_LPUART1_UART_Init(void)
void SystemClock_Config(void)
bool data_capture_operation
Definition ad4134_iio.c:96
UART_HandleTypeDef huart3
void MX_GPIO_Init(void)
HAL_StatusTypeDef HAL_Init(void)
void MX_SPI1_Init(void)
TIM_HandleTypeDef htim1
struct stm32_gpio_init_param stm32_gpio_reset_extra_init_params
Definition app_config_stm32.c:82
struct stm32_pwm_init_param stm32_pwm_extra_init_params
Definition app_config_stm32.c:76
struct stm32_gpio_init_param stm32_gpio_drdy_extra_init_params
Definition app_config_stm32.c:106
void ad777x_dma_rx_cplt(SAI_HandleTypeDef *hsai)
SAI DMA Receive Complete Callback function.
Definition app_config_stm32.c:211
struct stm32_gpio_init_param stm32_gpio_mode0_extra_init_params
Definition app_config_stm32.c:61
struct stm32_gpio_init_param stm32_gpio_error_extra_init_params
Definition app_config_stm32.c:111
struct stm32_gpio_init_param stm32_gpio_mode3_extra_init_params
Definition app_config_stm32.c:76
struct stm32_gpio_init_param stm32_gpio_dclk1_extra_init_params
Definition app_config_stm32.c:86
struct stm32_gpio_init_param stm32_gpio_mode2_extra_init_params
Definition app_config_stm32.c:71
struct stm32_gpio_init_param stm32_gpio_sync_in_extra_init_params
Definition app_config_stm32.c:96
struct iio_device_data * ad777x_iio_dev_data
Definition ad777x_iio.c:299
struct stm32_gpio_init_param stm32_gpio_mode1_extra_init_params
Definition app_config_stm32.c:66
void ad777x_dma_rx_half_cplt(SAI_HandleTypeDef *hsai)
SAI DMA Receive Half Complete Callback function.
Definition app_config_stm32.c:196
struct stm32_gpio_init_param stm32_gpio_dclk2_extra_init_params
Definition app_config_stm32.c:91
struct stm32_gpio_init_param stm32_gpio_dclk0_extra_init_params
Definition app_config_stm32.c:81
struct stm32_gpio_init_param stm32_gpio_convst_sar_extra_init_params
Definition app_config_stm32.c:101
void ad777x_configure_intr_priority(void)
Configure the interrupt priorities.
Definition app_config_mbed.c:135
Configuration file of nanodac firmware example program.