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 <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 TARGET_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 ADC */
47 #define RESET_PIN 9 // PG9
48 #define RESET_PORT 6 // PORT G
49 #define CNV_PIN 10 // PA10
50 #define CNV_PORT 0 // PORT A
51 #define BSY_PIN 7 // PG7
52 #define BSY_PORT 6 // PORT G
53 #define GPIO_TRIGGER_INT_PORT BSY_PORT
54 
55 /* STM32 SPI Specific parameters */
56 #define SPI_CSB 15 // PA15
57 #define STM32_SPI_CS_PORT 0 // PORTA
58 
59 #define SPI_CS_PORT_NUM 0 // PORTA
60 #define SPI_CS_PIN_NUM 15 // PA_15
61 
62 /* Peripheral IDs */
63 #define UART_ID 5 // UART5
64 #define I2C_DEVICE_ID 1 // I2C1
65 #define SPI_DEVICE_ID 1 // SPI1
66 
67 #define I2C_TIMING 0 // (Unused)
68 
69 /* Interrupt Callback parameters */
70 #define TRIGGER_INT_ID BSY_PIN
71 #define trigger_gpio_handle 0
72 #define BSY_GPIO_PRIORITY 1
73 
74 /* STM32 CNV PWM Specific parameters */
75 #define CNV_PWM_ID 1 // Timer 1
76 #define CNV_PWM_CHANNEL 3 // Channel 3
77 #define CNV_PWM_CLK_DIVIDER 2 // multiplier to get timer clock from PLCK1
78 #define PWM_GPIO_PORT CNV_PORT
79 #define PWM_GPIO_PIN CNV_PIN
80 
81 /* STM32 CS PWM Specific parameters */
82 #define CS_TIMER_ID 2
83 #define CS_TIMER_PRESCALER 0
84 #define CS_TIMER_CHANNEL 1
85 #define TIMER_2_CLK_DIVIDER 2
86 
87 /* Tx trigger Timer specifc parameters */
88 #define TIMER8_ID 8
89 #define TIMER_8_PRESCALER 0
90 #define TIMER_8_CLK_DIVIDER 2
91 #define TIMER_CHANNEL_1 1
92 
93 #define Rx_DMA_IRQ_ID DMA2_Stream0_IRQn
94 #define TxDMA_CHANNEL_NUM DMA_CHANNEL_7
95 #define RxDMA_CHANNEL_NUM DMA_CHANNEL_3
96 
97 #define AD7091R_DMA_NUM_CHANNELS 2
98 
99 /* Redefine the init params structure mapping wrt platform */
100 #define spi_extra_init_params stm32_spi_init_params
101 #define uart_extra_init_params stm32_uart_init_params
102 #define i2c_extra_init_params stm32_i2c_init_params
103 #define pwm_extra_init_params stm32_cnv_pwm_init_params
104 #define cnv_gpio_extra_init_param stm32_gpio_cnv_init_params
105 #define reset_gpio_extra_init_param stm32_gpio_reset_init_params
106 #define trigger_gpio_irq_extra_params stm32_trigger_gpio_irq_init_params
107 #define pwm_gpio_extra_init_params stm32_pwm_cnv_gpio_init_params
108 #define alt_bsy_gpio_extra_init_params stm32_gpio_gp0_extra_init_params
109 #define tx_trigger_extra_init_params stm32_tx_trigger_extra_init_params
110 #define cs_extra_init_params stm32_cs_extra_init_params
111 #define cs_pwm_gpio_extra_init_params stm32_cs_pwm_gpio_extra_init_params
112 #define vcom_extra_init_params stm32_vcom_extra_init_params
113 
114 /* Platform Ops */
115 #define trigger_gpio_irq_ops stm32_gpio_irq_ops
116 #define gpio_ops stm32_gpio_ops
117 #define spi_ops stm32_spi_ops
118 #define pwm_ops stm32_pwm_ops
119 #define uart_ops stm32_uart_ops
120 #define i2c_ops stm32_i2c_ops
121 #define dma_ops stm32_dma_ops
122 #define vcom_ops stm32_usb_uart_ops
123 
124 /* Maximum SPI clock rate in Hz */
125 #define MAX_SPI_SCLK 40000000
126 
127 /* Define the max possible sampling (or update) rate per channel for a given platform.
128  * Note: This is derived by testing the firmware on SDP-K1 controller
129  * board with STM32F469NI MCU.
130  * The max possible sampling rate can vary from board to board */
131 #if (INTERFACE_MODE == SPI_INTERRUPT)
132 #if (DATA_CAPTURE_MODE == CONTINUOUS_DATA_CAPTURE)
133 #define MAX_SAMPLING_RATE 40000
134 #else //Burst mode
135 #define MAX_SAMPLING_RATE 50000
136 #endif
137 #define PWM_DUTY_CYCLE_PERCENT 90
138 #define CNV_PWM_PRESCALER 3
139 #define PWM_DUTY_CYCLE_NSEC 360
140 #else //SPI_DMA
141 #define MAX_SAMPLING_RATE 830000
142 #define CHIP_SELECT_DUTY_CYCLE_NS 530
143 #define CNV_PWM_PRESCALER 1
144 #define PWM_DUTY_CYCLE_NSEC 250
145 #endif
146 
147 /* PWM configuration for 45MHz SPI clock */
148 #define TX_TRIGGER_PERIOD 400
149 #define TX_TRIGGER_DUTY_CYCLE_NS 30
150 
151 /******************************************************************************/
152 /********************** Variables and User Defined Data Types *****************/
153 /******************************************************************************/
154 extern struct stm32_uart_init_param stm32_uart_init_params;
155 extern struct stm32_gpio_irq_init_param stm32_trigger_gpio_irq_init_params;
156 extern struct stm32_spi_init_param stm32_spi_init_params;
157 extern struct stm32_i2c_init_param stm32_i2c_init_params;
158 extern struct stm32_gpio_init_param stm32_gpio_cnv_init_params;
159 extern struct stm32_gpio_init_param stm32_gpio_reset_init_params;
160 extern struct stm32_pwm_init_param stm32_cnv_pwm_init_params;
161 extern struct stm32_gpio_init_param stm32_pwm_cnv_gpio_init_params;
162 extern struct stm32_gpio_init_param stm32_gpio_gp0_extra_init_params;
163 extern UART_HandleTypeDef huart5;
164 extern TIM_HandleTypeDef htim1;
165 extern TIM_HandleTypeDef htim2;
166 extern USBD_HandleTypeDef hUsbDeviceHS;
167 
168 #if (INTERFACE_MODE == SPI_DMA)
169 extern DMA_HandleTypeDef hdma_tim8_ch1;
170 extern DMA_HandleTypeDef hdma_spi1_rx;
171 extern uint32_t rxdma_ndtr;
172 extern uint32_t dma_cycle_count;
173 
174 extern struct stm32_pwm_init_param stm32_cs_extra_init_params;
175 extern struct stm32_pwm_init_param stm32_tx_trigger_extra_init_params;
176 extern struct stm32_dma_channel rxdma_channel;
177 extern struct stm32_dma_channel txdma_channel;
178 extern struct stm32_gpio_init_param stm32_cs_pwm_gpio_extra_init_params;
179 extern struct stm32_usb_uart_init_param stm32_vcom_extra_init_params;
180 
181 void receivecomplete_callback(DMA_HandleTypeDef* hdma);
182 void halfcmplt_callback(DMA_HandleTypeDef* hdma);
183 void update_buff(uint32_t* local_buf, uint32_t* buf_start_addr);
184 void stm32_cs_output_gpio_config(bool is_gpio);
185 void tim8_config(void);
186 void tim2_config(void);
187 void stm32_timer_stop(void);
188 void stm32_timer_enable(void);
189 void stm32_abort_dma_transfer(void);
190 #endif
191 
192 void stm32_system_init(void);
193 void ad7091r8_pulse_convst_stm(void);
194 int ad7091r8_read_one_stm(uint8_t channel,
195  uint16_t* read_val);
196 void configure_intr_priority(void);
197 
198 #endif // APP_CONFIG_STM32_H_
UART_HandleTypeDef huart5
struct stm32_spi_init_param stm32_spi_init_params
Definition: app_config_stm32.c:40
struct stm32_gpio_init_param stm32_gpio_reset_init_params
Definition: app_config_stm32.c:67
struct stm32_gpio_irq_init_param stm32_trigger_gpio_irq_init_params
Definition: app_config_stm32.c:35
struct stm32_uart_init_param stm32_uart_init_params
Definition: app_config_stm32.c:30
struct stm32_dma_channel txdma_channel
Definition: app_config_stm32.c:29
TIM_HandleTypeDef htim1
TIM_HandleTypeDef htim2
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_cs_output_gpio_config(bool is_gpio)
Configures the chip select pin as output mode.
Definition: app_config_stm32.c:344
void stm32_system_init(void)
Initialize the STM32 system peripherals.
Definition: app_config_stm32.c:111
void halfcmplt_callback(DMA_HandleTypeDef *hdma)
Callback function to flag the capture of half the number of requested samples.
Definition: app_config_stm32.c:233
void tim8_config(void)
Configure Tx Trigger timer.
Definition: app_config_stm32.c:412
struct stm32_pwm_init_param stm32_cs_extra_init_params
Definition: app_config_stm32.c:125
void stm32_timer_enable(void)
Starts the timer signal generation for PWM and OC channels all at once.
Definition: app_config_stm32.c:267
void receivecomplete_callback(DMA_HandleTypeDef *hdma)
Callback function to flag the capture of number of requested samples.
Definition: app_config_stm32.c:306
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
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_gpio_init_param stm32_cs_pwm_gpio_extra_init_params
Definition: app_config_stm32.c:89
struct stm32_gpio_init_param stm32_gpio_gp0_extra_init_params
Definition: app_config_stm32.c:66
uint8_t local_buf[MAX_LOCAL_BUF_SIZE]
Definition: ad405x_iio.c:177
void tim2_config(void)
Configure CS timer.
Definition: app_config_stm32.c:224
struct stm32_gpio_init_param stm32_gpio_cnv_init_params
Definition: app_config_stm32.c:70
USBD_HandleTypeDef hUsbDeviceHS
void configure_intr_priority(void)
Prioritizes the UART1 interrupt over the other peripheral interrupts.
Definition: app_config_stm32.c:475
struct stm32_pwm_init_param stm32_cnv_pwm_init_params
Definition: app_config_stm32.c:94
struct stm32_usb_uart_init_param stm32_vcom_extra_init_params
Definition: app_config_stm32.c:49
void ad7091r8_pulse_convst_stm(void)
Pull the CONVST line down then up.
Definition: app_config_stm32.c:422
int ad7091r8_read_one_stm(uint8_t channel, uint16_t *read_val)
Read one sample.
Definition: app_config_stm32.c:434
struct stm32_i2c_init_param stm32_i2c_init_params
Definition: app_config_stm32.c:65
struct stm32_gpio_init_param stm32_pwm_cnv_gpio_init_params
Definition: app_config_stm32.c:76
Configuration file of nanodac firmware example program.