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 <stdint.h>
20
21#include "stm32_hal.h"
22#include "stm32_i2c.h"
23#include "stm32_spi.h"
24#include "stm32_gpio.h"
25#include "stm32_uart.h"
26#include "stm32_dma.h"
27#include "stm32_gpio_irq.h"
28#include "app_config.h"
29#include "ad5706r.h"
30#include "stm32_usb_uart.h"
31
32/******************************************************************************/
33/********************** Macros and Constants Definition ***********************/
34/******************************************************************************/
35/* Note: The SDP-K1 board with the STM32F469NI MCU has been used
36* for developing the firmware. The below parameters will change depending
37* on the controller used. */
38#define HW_CARRIER_NAME SDP-K1
39
40/* Pin mapping for AD5706R w.r.t Arduino Headers */
41#define SPI_DEVICE_ID 1 // SPI1
42#define SPI_CSB 15 // PA_15
43#define SPI_CS_PORT_BASE GPIOA
44#define SPI_CS_PORT_NUM 0 // PORTA = 0
45
46#define I2C_DEV_ID 1 // I2C1
47#define UART_MODULE 5 // UART5
48#define UART_IRQ UART5_IRQn
49
50#define GPIO_AD0 11 // PA11
51#define GPIO_AD1 9 // PG9
52#define GPIO_LDAC_TG 15 // PB15
53#define GPIO_RESET 11 // PG11
54#define GPIO_SHUTDOWN 10 // PG10
55#define GPIO_DAC_UPDATE 12 // PD12
56#define AD0_PORT 0 // PORTA
57#define AD1_PORT 6 // PORTG
58#define LDAC_TG_PORT 1 // PORTB
59#define RESET_PORT 6 // PORTG
60#define SHUTDOWN_PORT 6 // PORTG
61#define DAC_UPDATE_PORT 3 // PORTD
62
63/* LDAC Timer configurations */
64#define PWM_TIMER_ID 1 // Timer 1
65#define TRIGGER_INT_ID GPIO_DAC_UPDATE
66#define TIMER_1_PRESCALER 1
67#define TIMER_1_CLK_DIVIDER 2
68#define TIMER_CHANNEL_3 3
69#define PWM_TIMER_HANDLE htim1
70
71/* DAC Update timer configurations */
72#define DAC_UPDATE_TIMER_ID 4 // Timer 4
73#define TIMER_CHANNEL_1 1 // Channel 1
74#define TIMER_4_PRESCALER 0
75#define TIMER_4_CLK_DIVIDER 2
76#define DAC_UPDATE_TIMER_HANDLE htim4
77
78/* Tx Trigger configurations for 20MHz SPI clock */
79#define TIMER8_ID 8
80#define TX_TRIGGER_PERIOD 410 // TODO: Update this value based on the Max SPI Clock
81#define TX_TRIGGER_DUTY_RATIO 10
82#define TIMER_8_PRESCALER 0
83#define TIMER_8_CLK_DIVIDER 2
84#define TIMER8_HANDLE htim8
85
86/* CS PWM configurations */
87#define CS_TIMER_ID 2
88#define CS_TIMER_PRESCALER 0
89#define CS_TIMER_CHANNEL 1
90#define TIMER_2_CLK_DIVIDER 2
91#define CS_TIMER_HANDLE htim2
92
93#define I2C_TIMING 0 // Unused
94
95#define DAC_UPDATE_GPIO_PRIORITY 1
96#define trigger_gpio_handle 0
97
98#define AD5706_DMA_NUM_CHANNELS 2
99#define AD5706_TxDMA_CHANNEL_NUM DMA_CHANNEL_7
100#define AD5706_RxDMA_CHANNEL_NUM DMA_CHANNEL_3
101#define Rx_DMA_IRQ_ID DMA2_Stream0_IRQn
102
103/* Redefine the init params structure mapping w.r.t. platform */
104#ifdef USE_VIRTUAL_COM_PORT
105#define vcom_extra_init_params stm32_vcom_extra_init_params
106#define vcom_ops stm32_usb_uart_ops
107#else
108#define uart_extra_init_params stm32_uart_extra_init_params
109#define uart_ops stm32_uart_ops
110#endif
111#define spi_extra_init_params stm32_spi_extra_init_params
112#define i2c_extra_init_params stm32_i2c_extra_init_params
113#define gpio_ad0_extra_params stm32_gpio_ad0_init_params
114#define gpio_ad1_extra_params stm32_gpio_ad1_init_params
115#define gpio_ldac_tg_extra_params stm32_gpio_ldac_tg_init_params
116#define gpio_shutdown_extra_params stm32_gpio_shutdown_init_params
117#define gpio_reset_extra_params stm32_gpio_reset_init_params
118#define ldac_pwm_extra_init_params stm32_ldac_pwm_init_params
119#define dac_update_pwm_extra_init_params stm32_dac_update_pwm_init_params
120#define ldac_pwm_gpio_extra_init_params stm32_ldac_pwm_gpio_extra_init_params
121#define dac_update_pwm_gpio_extra_init_params stm32_dac_update_pwm_gpio_extra_init_params
122#if (INTERFACE_MODE == SPI_DMA)
123#define tx_trigger_extra_init_params stm32_tx_trigger_extra_init_params
124#define csb_gpio_extra_init_params stm32_cs_gpio_extra_init_params
125#define cs_extra_init_params stm32_cs_extra_init_params
126#define dma_ops stm32_dma_ops
127#else
128#define trigger_gpio_irq_extra_params stm32_trigger_gpio_irq_init_params
129#define trigger_gpio_irq_ops stm32_gpio_irq_ops
130#endif
131#define gpio_ops stm32_gpio_ops
132#define gpio_ops stm32_gpio_ops
133#define spi_ops stm32_spi_ops
134#define i2c_ops stm32_i2c_ops
135#define pwm_ops stm32_pwm_ops
136
137// TODO: Update this value after SPI clock issues have been resolved
138#define MAX_SPI_SCLK_FREQ 20000000
139#if (INTERFACE_MODE == SPI_DMA)
140#define AD5706_MAX_UPDATE_RATE 500000 // TODO: Update the Max rate based on the max SPI clock
141#else
142#define AD5706_MAX_UPDATE_RATE 50000
143#endif
144
145/******************************************************************************/
146/********************** Public/Extern Declarations ****************************/
147/******************************************************************************/
148
149void stm32_system_init(void);
151
152extern struct stm32_spi_init_param stm32_spi_extra_init_params;
153extern struct stm32_i2c_init_param stm32_i2c_extra_init_params;
154extern struct stm32_gpio_init_param stm32_gpio_ad0_init_params;
155extern struct stm32_gpio_init_param stm32_gpio_ad1_init_params;
156extern struct stm32_gpio_init_param stm32_gpio_ldac_tg_init_params;
157extern struct stm32_gpio_init_param stm32_gpio_shutdown_init_params;
158extern struct stm32_gpio_init_param stm32_gpio_reset_init_params;
159extern struct stm32_pwm_init_param stm32_ldac_pwm_init_params;
160extern struct stm32_pwm_init_param stm32_dac_update_pwm_init_params;
161extern struct stm32_gpio_init_param stm32_ldac_pwm_gpio_extra_init_params;
162extern struct stm32_gpio_init_param stm32_dac_update_pwm_gpio_extra_init_params;
163
164extern TIM_HandleTypeDef PWM_TIMER_HANDLE;
165extern TIM_HandleTypeDef DAC_UPDATE_TIMER_HANDLE;
166
167#if (INTERFACE_MODE == SPI_DMA)
168void ad5706r_rx_cplt_callback(DMA_HandleTypeDef* hdma);
169int ad5706r_abort_dma_transfers(struct ad5706r_dev *device);
170int ad5706r_timers_enable(struct ad5706r_dev *device);
172
173extern DMA_HandleTypeDef hdma_spi1_rx;
174extern DMA_HandleTypeDef hdma_tim8_ch1;
175extern TIM_HandleTypeDef TIMER8_HANDLE;
176extern TIM_HandleTypeDef CS_TIMER_HANDLE;
177extern struct stm32_dma_channel txdma_channel;
178extern struct stm32_dma_channel rxdma_channel;
179extern struct stm32_pwm_init_param stm32_tx_trigger_extra_init_params;
180extern struct stm32_gpio_init_param stm32_cs_gpio_extra_init_params;
181extern struct stm32_pwm_init_param stm32_cs_extra_init_params;
182extern struct no_os_dma_init_param ad5706r_dma_init_param;
183extern struct stm32_spi_init_param* spi_init_param;
184extern uint8_t n_bytes;
185#else
186extern struct stm32_gpio_irq_init_param stm32_trigger_gpio_irq_init_params;
187#endif // INTERFACE_MODE
188
189#ifdef USE_VIRTUAL_COM_PORT
191extern USBD_HandleTypeDef hUsbDeviceHS;
193#else
194extern UART_HandleTypeDef huart5;
195extern struct stm32_uart_init_param stm32_uart_extra_init_params;
196#endif // USE_VIRTUAL_COM_PORT
197extern bool hw_mode_enabled;
198extern bool sw_mode_enabled;
199
200#endif /* APP_CONFIG_STM32_H_ */
UART_HandleTypeDef huart5
#define TIMER8_HANDLE
Definition app_config_stm32.h:84
DMA_HandleTypeDef hdma_tim8_ch1
struct stm32_pwm_init_param stm32_ldac_pwm_init_params
Definition app_config_stm32.c:77
struct stm32_dma_channel rxdma_channel
Definition app_config_stm32.c:136
USBD_HandleTypeDef hUsbDeviceHS
void stm32_system_init(void)
Initialize the STM32 system peripherals.
Definition app_config_stm32.c:176
struct stm32_gpio_init_param stm32_gpio_reset_init_params
Definition app_config_stm32.c:72
struct stm32_pwm_init_param stm32_tx_trigger_extra_init_params
Definition app_config_stm32.c:99
struct stm32_usb_uart_init_param stm32_vcom_extra_init_params
Definition app_config_stm32.c:38
DMA_HandleTypeDef hdma_spi1_rx
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_pwm_init_param stm32_cs_extra_init_params
Definition app_config_stm32.c:120
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:43
void SystemClock_Config(void)
struct stm32_dma_channel txdma_channel
Definition app_config_stm32.c:118
void MX_USB_DEVICE_Init(void)
int ad5706r_init_tx_trigger(void)
Init Tx Trigger PWM.
Definition app_config_stm32.c:321
struct stm32_gpio_init_param stm32_cs_gpio_extra_init_params
Definition app_config_stm32.c:174
#define CS_TIMER_HANDLE
Definition app_config_stm32.h:91
bool sw_mode_enabled
Definition ad5706r_iio.c:521
bool hw_mode_enabled
Definition ad5706r_iio.c:518
struct stm32_spi_init_param * spi_init_param
Definition ad3530r_iio.c:319
struct no_os_dma_init_param ad5706r_dma_init_param
Definition app_config.c:198
struct stm32_pwm_init_param stm32_dac_update_pwm_init_params
Definition app_config_stm32.c:86
uint8_t n_bytes
Definition ad5706r_iio.c:485
struct stm32_gpio_init_param stm32_dac_update_pwm_gpio_extra_init_params
Definition app_config_stm32.c:113
#define DAC_UPDATE_TIMER_HANDLE
Definition app_config_stm32.h:76
struct stm32_gpio_init_param stm32_gpio_ldac_tg_init_params
Definition app_config_stm32.c:56
#define PWM_TIMER_HANDLE
Definition app_config_stm32.h:69
void ad5706r_rx_cplt_callback(DMA_HandleTypeDef *hdma)
Callback function to flag the transfer of number of requested samples.
Definition app_config_stm32.c:247
int ad5706r_abort_dma_transfers(struct ad5706r_dev *device)
Abort DMA Transfers.
Definition app_config_stm32.c:297
int ad5706r_timers_enable(struct ad5706r_dev *device)
Starts the timer signal generation.
Definition app_config_stm32.c:257
struct stm32_gpio_init_param stm32_gpio_shutdown_init_params
Definition app_config_stm32.c:62
struct stm32_gpio_init_param stm32_gpio_ad1_init_params
Definition app_config_stm32.c:50
struct stm32_gpio_init_param stm32_ldac_pwm_gpio_extra_init_params
Definition app_config_stm32.c:106
struct stm32_gpio_init_param stm32_gpio_ad0_init_params
Definition app_config_stm32.c:44
struct ad5933_dev * device
Definition main.c:90
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