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 <stdint.h>
21#include "stm32_uart.h"
22#include "stm32_spi.h"
23#include "stm32_gpio.h"
24#include "stm32_irq.h"
25#include "stm32_pwm.h"
26#include "stm32_i2c.h"
27#include "stm32_gpio_irq.h"
28#include "stm32_dma.h"
29#include "stm32_usb_uart.h"
30#include "app_config.h"
31
32/******************************************************************************/
33/********************** Macros and Constants Definition ***********************/
34/******************************************************************************/
35
36/* Note: The SDP-K1 board with the STM32F469NI MCU has been used
37 * for developing the firmware. The below parameters will change depending
38 * on the controller used. */
39#define HW_CARRIER_NAME SDP_K1
40
41/* STM32 UART specific parameters */
42#define APP_UART_HANDLE &huart5
43#define UART_IRQ_ID UART5_IRQn
44#define APP_UART_USB_HANDLE &hUsbDeviceHS
45
46/* GPIO Pins associated with DAC */
47#define RESET_PIN 11 // PG11
48#define RESET_PORT 6 // PORTG
49#define LDAC_PIN 10 // PA10
50#define LDAC_PORT 0 // PORT A
51#define GPIO_TRIGGER_INT_PORT 0
52
53/* STM32 SPI Specific parameters */
54#define SPI_DEVICE_ID 1 // SPI1
55#define SPI_CSB 15 // PA15
56#define STM32_SPI_CS_PORT 0 // PORTA
57
58/* STM32 I2C Specific parameters */
59#define I2C_DEVICE_ID 1 // I2C1
60#define I2C_TIMING 0 // (Unused)
61
62/* Interrupt Callback parameters */
63#define IRQ_CTRL_ID 10
64#define TRIGGER_INT_ID 10
65#define trigger_gpio_handle 0
66#define LDAC_GPIO_PRIORITY 1
67
68/* STM32 LDAC PWM Specific parameters */
69#define LDAC_PWM_ID 1 // Timer 1
70#define LDAC_PWM_CHANNEL 3 // Channel 3
71#define LDAC_PWM_CLK_DIVIDER 2 // multiplier to get timer clock from PLCK1
72#define PWM_GPIO_PORT LDAC_PORT
73#define PWM_GPIO_PIN LDAC_PIN
74#define LDAC_PWM_HANDLE htim1
75
76/* Peripheral IDs (Unused) */
77#define UART_ID 0
78
79/* Tx trigger Timer specific parameters */
80#define TIMER8_ID 8
81#define TIMER_8_PRESCALER 0
82#define TIMER_8_CLK_DIVIDER 2
83#define TIMER_CHANNEL_1 1
84#define TIMER8_HANDLE htim8
85
86#define Rx_DMA_IRQ_ID DMA2_Stream0_IRQn
87#define TxDMA_CHANNEL_NUM DMA_CHANNEL_7
88#define RxDMA_CHANNEL_NUM DMA_CHANNEL_3
89
90#define DMA_NUM_CHANNELS 2
91
92/* Redefine the init params structure mapping wrt platform */
93#define spi_extra_init_params stm32_spi_init_params
94#define uart_extra_init_params stm32_uart_init_params
95#define i2c_extra_init_params stm32_i2c_init_params
96#define pwm_extra_init_params stm32_ldac_pwm_init_params
97#define gpio_ldac_extra_init_params stm32_gpio_ldac_init_params
98#define gpio_reset_extra_init_params stm32_gpio_reset_init_params
99#define csb_gpio_extra_init_params stm32_csb_gpio_init_params
100#define trigger_gpio_irq_extra_params stm32_trigger_gpio_irq_init_params
101#define gpio_pwm_extra_init_params stm32_pwm_ldac_gpio_init_params
102#define tx_trigger_extra_init_params stm32_tx_trigger_extra_init_params
103#define vcom_extra_init_params stm32_vcom_extra_init_params
104
105/* Platform Ops */
106#define trigger_gpio_irq_ops stm32_gpio_irq_ops
107#define gpio_ops stm32_gpio_ops
108#define spi_ops stm32_spi_ops
109#define pwm_ops stm32_pwm_ops
110#define uart_ops stm32_uart_ops
111#define i2c_ops stm32_i2c_ops
112#define dma_ops stm32_dma_ops
113#define vcom_ops stm32_usb_uart_ops
114
115/* Maximum SPI clock frequency in Hz */
116#define MAX_SPI_SCLK 22500000
117
118/* Define the max possible sampling (or update) rate per channel for a given platform.
119 * Note: This is derived by testing the firmware on SDP-K1 controller
120 * board with STM32F469NI MCU.
121 * The max possible sampling rate can vary from board to board */
122#if (INTERFACE_MODE == SPI_INTERRUPT)
123#define MAX_SAMPLING_RATE 40000
124#define LDAC_PWM_DUTY_CYCLE_PERCENT 50
125#define LDAC_PWM_PRESCALER 3
126#else //SPI_DMA
127#define MAX_SAMPLING_RATE 560000
128#define MAX_SAMPLING_RATE_STREAMING_MODE 1400000
129#define LDAC_PULSE_WIDTH_NS 250
130#define LDAC_PWM_PRESCALER 3
131#endif
132
133/* PWM configuration for 22.5MHz SPI clock */
134#define TX_TRIGGER_PERIOD 400
135#define TX_TRIGGER_DUTY_CYCLE_NS 50
136
137/* Number of pulse repetitions for tx timer in one-pulse
138 * mode (bytes per sample(2) + address bytes (2) - 1)
139 */
140#define NUM_PULSE_REPETITIONS 3
141
142/******************************************************************************/
143/********************** Variables and User Defined Data Types *****************/
144/******************************************************************************/
145extern struct stm32_uart_init_param stm32_uart_init_params;
146extern struct stm32_gpio_irq_init_param stm32_trigger_gpio_irq_init_params;
147extern struct stm32_spi_init_param stm32_spi_init_params;
148extern struct stm32_i2c_init_param stm32_i2c_init_params;
149extern struct stm32_gpio_init_param stm32_gpio_ldac_init_params;
150extern struct stm32_gpio_init_param stm32_gpio_reset_init_params;
151extern struct stm32_pwm_init_param stm32_ldac_pwm_init_params;
152extern struct stm32_gpio_init_param stm32_pwm_ldac_gpio_init_params;
153extern UART_HandleTypeDef huart5;
154extern USBD_HandleTypeDef hUsbDeviceHS;
155extern TIM_HandleTypeDef LDAC_PWM_HANDLE;
156
157#if (INTERFACE_MODE == SPI_DMA)
158extern DMA_HandleTypeDef hdma_tim8_ch1;
159extern DMA_HandleTypeDef hdma_spi1_rx;
160extern TIM_HandleTypeDef TIMER8_HANDLE;
161
162extern struct stm32_gpio_init_param stm32_csb_gpio_init_params;
163extern struct stm32_pwm_init_param stm32_tx_trigger_extra_init_params;
165extern struct stm32_dma_channel rxdma_channel;
166extern struct stm32_dma_channel txdma_channel_single_instr_mode;
167extern struct stm32_dma_channel txdma_channel_stream_mode;
168
169void receivecomplete_callback(DMA_HandleTypeDef* hdma);
170void tim8_config(void);
171int stm32_timer_stop(void);
172int stm32_timer_enable(void);
174#endif
175
176void stm32_system_init(void);
177int reconfig_stm32_params(void);
178
179#endif // APP_CONFIG_STM32_H_
int stm32_timer_stop(void)
Stop generating timer signals.
Definition app_config_stm32.c:281
UART_HandleTypeDef huart5
#define TIMER8_HANDLE
Definition app_config_stm32.h:84
int stm32_timer_enable(void)
Starts the timer signal generation for PWM.
Definition app_config_stm32.c:258
struct stm32_gpio_init_param stm32_gpio_ldac_init_params
Definition app_config_stm32.c:59
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 txdma_channel_single_instr_mode
Definition app_config_stm32.c:116
struct stm32_dma_channel rxdma_channel
Definition app_config_stm32.c:136
USBD_HandleTypeDef hUsbDeviceHS
struct stm32_spi_init_param stm32_spi_init_params
Definition app_config_stm32.c:48
void stm32_system_init(void)
Initialize the STM32 system peripherals.
Definition app_config_stm32.c:176
void tim8_config(void)
Configure Tx Trigger timer for slave mode operation, one-pulse mode and to generate DMA requests.
Definition app_config_stm32.c:245
void receivecomplete_callback(DMA_HandleTypeDef *hdma)
Callback function to flag the transfer of number of requested samples.
Definition app_config_stm32.c:340
#define LDAC_PWM_HANDLE
Definition app_config_stm32.h:74
struct stm32_gpio_init_param stm32_gpio_reset_init_params
Definition app_config_stm32.c:72
struct stm32_dma_channel txdma_channel_stream_mode
Definition app_config_stm32.c:126
struct stm32_pwm_init_param stm32_tx_trigger_extra_init_params
Definition app_config_stm32.c:99
int stm32_abort_dma_transfer(void)
Abort DMA Transfers.
Definition app_config_stm32.c:315
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_init_param stm32_pwm_ldac_gpio_init_params
Definition app_config_stm32.c:65
struct stm32_gpio_irq_init_param stm32_trigger_gpio_irq_init_params
Definition app_config_stm32.c:43
struct stm32_gpio_init_param stm32_csb_gpio_init_params
Definition app_config_stm32.c:93
struct stm32_uart_init_param stm32_uart_init_params
Definition app_config_stm32.c:33
struct stm32_i2c_init_param stm32_i2c_init_params
Definition app_config_stm32.c:54
int reconfig_stm32_params(void)
Reconfigure the STM32 specific system parameters with change in data streaming mode.
Definition app_config_stm32.c:217
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