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 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 CNV_PWM_HANDLE htim1
79#define PWM_GPIO_PORT CNV_PORT
80#define PWM_GPIO_PIN CNV_PIN
81
82/* STM32 CS PWM Specific parameters */
83#define CS_TIMER_ID 2
84#define CS_TIMER_PRESCALER 0
85#define CS_TIMER_CHANNEL 1
86#define TIMER_2_CLK_DIVIDER 2
87#define CS_TIMER_HANDLE htim2
88
89/* Tx trigger Timer specifc parameters */
90#define TIMER8_ID 8
91#define TIMER_8_PRESCALER 0
92#define TIMER_8_CLK_DIVIDER 2
93#define TIMER_CHANNEL_1 1
94#define TIMER8_HANDLE htim8
95
96#define Rx_DMA_IRQ_ID DMA2_Stream0_IRQn
97#define TxDMA_CHANNEL_NUM DMA_CHANNEL_7
98#define RxDMA_CHANNEL_NUM DMA_CHANNEL_3
99
100#define AD7091R_DMA_NUM_CHANNELS 2
101
102/* Redefine the init params structure mapping wrt platform */
103#define spi_extra_init_params stm32_spi_init_params
104#define uart_extra_init_params stm32_uart_init_params
105#define i2c_extra_init_params stm32_i2c_init_params
106#define pwm_extra_init_params stm32_cnv_pwm_init_params
107#define cnv_gpio_extra_init_param stm32_gpio_cnv_init_params
108#define reset_gpio_extra_init_param stm32_gpio_reset_init_params
109#define trigger_gpio_irq_extra_params stm32_trigger_gpio_irq_init_params
110#define pwm_gpio_extra_init_params stm32_pwm_cnv_gpio_init_params
111#define alt_bsy_gpio_extra_init_params stm32_gpio_gp0_extra_init_params
112#define tx_trigger_extra_init_params stm32_tx_trigger_extra_init_params
113#define cs_extra_init_params stm32_cs_extra_init_params
114#define cs_pwm_gpio_extra_init_params stm32_cs_pwm_gpio_extra_init_params
115#define vcom_extra_init_params stm32_vcom_extra_init_params
116
117/* Platform Ops */
118#define trigger_gpio_irq_ops stm32_gpio_irq_ops
119#define gpio_ops stm32_gpio_ops
120#define spi_ops stm32_spi_ops
121#define pwm_ops stm32_pwm_ops
122#define uart_ops stm32_uart_ops
123#define i2c_ops stm32_i2c_ops
124#define dma_ops stm32_dma_ops
125#define vcom_ops stm32_usb_uart_ops
126
127/* Maximum SPI clock rate in Hz */
128#define MAX_SPI_SCLK 40000000
129
130/* Define the max possible sampling (or update) rate per channel for a given platform.
131 * Note: This is derived by testing the firmware on SDP-K1 controller
132 * board with STM32F469NI MCU.
133 * The max possible sampling rate can vary from board to board */
134#if (INTERFACE_MODE == SPI_INTERRUPT)
135#if (DATA_CAPTURE_MODE == CONTINUOUS_DATA_CAPTURE)
136#define MAX_SAMPLING_RATE 40000
137#else //Burst mode
138#define MAX_SAMPLING_RATE 50000
139#endif
140#define PWM_DUTY_CYCLE_PERCENT 90
141#define CNV_PWM_PRESCALER 3
142#define PWM_DUTY_CYCLE_NSEC 360
143#else //SPI_DMA
144#define MAX_SAMPLING_RATE 830000
145#define CHIP_SELECT_DUTY_CYCLE_NS 530
146#define CNV_PWM_PRESCALER 1
147#define PWM_DUTY_CYCLE_NSEC 250
148#endif
149
150/* PWM configuration for 45MHz SPI clock */
151#define TX_TRIGGER_PERIOD 400
152#define TX_TRIGGER_DUTY_CYCLE_NS 30
153
154/******************************************************************************/
155/********************** Variables and User Defined Data Types *****************/
156/******************************************************************************/
157extern struct stm32_uart_init_param stm32_uart_init_params;
158extern struct stm32_gpio_irq_init_param stm32_trigger_gpio_irq_init_params;
159extern struct stm32_spi_init_param stm32_spi_init_params;
160extern struct stm32_i2c_init_param stm32_i2c_init_params;
161extern struct stm32_gpio_init_param stm32_gpio_cnv_init_params;
162extern struct stm32_gpio_init_param stm32_gpio_reset_init_params;
163extern struct stm32_pwm_init_param stm32_cnv_pwm_init_params;
164extern struct stm32_gpio_init_param stm32_pwm_cnv_gpio_init_params;
165extern struct stm32_gpio_init_param stm32_gpio_gp0_extra_init_params;
166extern UART_HandleTypeDef huart5;
167extern TIM_HandleTypeDef htim1;
168extern TIM_HandleTypeDef htim2;
169extern USBD_HandleTypeDef hUsbDeviceHS;
170
171#if (INTERFACE_MODE == SPI_DMA)
172extern DMA_HandleTypeDef hdma_tim8_ch1;
173extern DMA_HandleTypeDef hdma_spi1_rx;
174extern TIM_HandleTypeDef htim8;
175extern uint32_t rxdma_ndtr;
176extern uint32_t dma_cycle_count;
177
178extern struct stm32_pwm_init_param stm32_cs_extra_init_params;
179extern struct stm32_pwm_init_param stm32_tx_trigger_extra_init_params;
180extern struct stm32_dma_channel rxdma_channel;
181extern struct stm32_dma_channel txdma_channel;
182extern struct stm32_gpio_init_param stm32_cs_pwm_gpio_extra_init_params;
184
185void receivecomplete_callback(DMA_HandleTypeDef* hdma);
186void halfcmplt_callback(DMA_HandleTypeDef* hdma);
187void update_buff(uint32_t* local_buf, uint32_t* buf_start_addr);
188void stm32_cs_output_gpio_config(bool is_gpio);
189void tim8_config(void);
190void tim2_config(void);
191void stm32_timer_stop(void);
192void stm32_timer_enable(void);
193void stm32_abort_dma_transfer(void);
194#endif
195
196void stm32_system_init(void);
198int ad7091r8_read_one_stm(uint8_t channel,
199 uint16_t* read_val);
200void configure_intr_priority(void);
201
202#endif // APP_CONFIG_STM32_H_
int stm32_timer_stop(void)
Stop generating timer signals.
Definition app_config_stm32.c:281
UART_HandleTypeDef huart5
int stm32_timer_enable(void)
Starts the timer signal generation for PWM.
Definition app_config_stm32.c:258
DMA_HandleTypeDef hdma_tim8_ch1
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
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
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_irq_init_param stm32_trigger_gpio_irq_init_params
Definition app_config_stm32.c:43
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
volatile int dma_cycle_count
Definition app_config_stm32.c:242
uint32_t rxdma_ndtr
Definition app_config_stm32.c:245
void update_buff(uint8_t *local_buf, uint8_t *buf_start_addr)
Update buffer index.
Definition app_config_stm32.c:499
void stm32_cs_output_gpio_config(bool is_gpio)
Configures the chip select pin as output mode.
Definition app_config_stm32.c:309
void halfcmplt_callback(DMA_HandleTypeDef *hdma)
Callback function to flag the capture of Half the number of requested samples.
Definition app_config_stm32.c:389
struct stm32_pwm_init_param stm32_cs_extra_init_params
Definition app_config_stm32.c:120
struct stm32_gpio_init_param stm32_cs_pwm_gpio_extra_init_params
Definition app_config_stm32.c:167
struct stm32_gpio_init_param stm32_gpio_gp0_extra_init_params
Definition app_config_stm32.c:144
uint8_t local_buf[MAX_LOCAL_BUF_SIZE]
Definition ad405x_support.c:42
struct stm32_dma_channel txdma_channel
Definition app_config_stm32.c:115
TIM_HandleTypeDef htim1
TIM_HandleTypeDef htim2
TIM_HandleTypeDef htim8
void tim2_config(void)
Configure CS timer.
Definition app_config_stm32.c:223
struct stm32_gpio_init_param stm32_gpio_cnv_init_params
Definition app_config_stm32.c:70
void configure_intr_priority(void)
Prioritizes the UART1 interrupt over the other peripheral interrupts.
Definition app_config_stm32.c:473
struct stm32_pwm_init_param stm32_cnv_pwm_init_params
Definition app_config_stm32.c:94
void ad7091r8_pulse_convst_stm(void)
Pull the CONVST line down then up.
Definition app_config_stm32.c:420
int ad7091r8_read_one_stm(uint8_t channel, uint16_t *read_val)
Read one sample.
Definition app_config_stm32.c:432
struct stm32_gpio_init_param stm32_pwm_cnv_gpio_init_params
Definition app_config_stm32.c:76
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