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_irq.h"
24#include "stm32_gpio_irq.h"
25#include "stm32_spi.h"
26#include "stm32_gpio.h"
27#include "stm32_uart.h"
28#include "stm32_pwm.h"
29#include "stm32_dma.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 TARGET_NAME SDP_K1
39
40/* Pin mapping for AD4052 w.r.t Arduino Headers */
41#define I2C_DEV_ID 1 // I2C1
42#define UART_MODULE 5 // UART5
43#define UART_IRQ UART5_IRQn
44#define SPI_DEVICE_ID 1 // SPI1
45#define SPI_CS_PIN_NUM 15 // PA_15
46#define SPI_CS_PORT_BASE GPIOA
47#define SPI_CS_PORT_NUM 0 // PORTA = 0
48#define CNV_PIN_NUM 10 // PA_10
49#define CNV_PORT_NUM 0 // PORTA = 0
50#define CNV_PORT_BASE GPIOA
51#define GP0_PIN_NUM 15 // PB_15
52#define GP0_PORT_NUM 1 // PORTB = 1
53#define GP1_PIN_NUM 10 // PG_10
54#define GP1_PORT_NUM 6 // PORTG = 6
55#define BSY_PIN_NUM GP0_PIN_NUM
56#define BSY_PORT_NUM GP0_PORT_NUM
57#define RESET_PIN_NUM 9 // PG_9
58#define RESET_PORT_NUM 6 // PORTG = 6
59#define TRIGGER_INT_ID GP0_PIN_NUM
60#define TRIGGER_GPIO_PORT 0 // Unused macro
61#define TRIGGER_GPIO_PIN GP0_PIN_NUM
62#define MAX_SPI_SCLK 22500000
63
64#define gpio_ops stm32_gpio_ops
65#define spi_ops stm32_spi_ops
66#define i2c_ops stm32_i2c_ops
67#define uart_ops stm32_uart_ops
68#define pwm_ops stm32_pwm_ops
69#define trigger_gpio_irq_ops stm32_gpio_irq_ops
70#define dma_ops stm32_dma_ops
71#define vcom_ops stm32_usb_uart_ops
72#define trigger_gpio_handle 0 // Unused macro
73
74/* Timer specific macros used for calculating pwm
75 * period and duty cycle */
76#define TIMER_1_PRESCALER 1
77#define TIMER_2_PRESCALER 0
78#define TIMER_1_CLK_DIVIDER 2
79#define TIMER_2_CLK_DIVIDER 2
80#define TIMER_8_PRESCALER 0
81#define TIMER_8_CLK_DIVIDER 2
82
83/* Timer Channels */
84#define TIMER_CHANNEL_1 1
85#define TIMER_CHANNEL_2 2
86#define TIMER_CHANNEL_3 3
87
88#define TIMER1_ID 1
89#define TIMER2_ID 2
90#define TIMER8_ID 8
91
92#define TIMER1_HANDLE htim1
93#define TIMER2_HANDLE htim2
94#define TIMER8_HANDLE htim8
95
96#define Rx_DMA_IRQ_ID DMA2_Stream0_IRQn
97#define AD469x_TxDMA_CHANNEL_NUM DMA_CHANNEL_7
98#define AD469x_RxDMA_CHANNEL_NUM DMA_CHANNEL_3
99
100/* Define the max possible sampling (or output data) rate for a given platform.
101 * This is also used to find the time period to trigger a periodic conversion event.
102 * Note: Max possible ODR is 500KSPS per channel for burst/continuous data capture on
103 * IIO client. This is derived by testing the firmware on STM32F469NI MCU @22Mhz SPI clock.
104 * The max possible ODR can vary from board to board and data continuity is not guaranteed
105 * above this ODR on IIO oscilloscope
106 */
107#if (INTERFACE_MODE == SPI_INTERRUPT)
108#define SAMPLING_RATE (50000)
109#define CONV_TRIGGER_DUTY_CYCLE_NSEC(x) (x / 10)
110#else
111#define SAMPLING_RATE (500000)
112#define CHIP_SELECT_DUTY_CYCLE_NS 300
113#endif
114#define CONV_TRIGGER_PERIOD_NSEC(x) (((float)(1.0 / x) * 1000000) * 1000)
115
116#define AD469x_DMA_NUM_CHANNELS 2
117
118/* PWM configuration for 22.5MHz SPI clock */
119#define TX_TRIGGER_PERIOD 406
120#define TX_TRIGGER_DUTY_RATIO 50
121
122#define CNV_DUTY_RATIO_NS 690
123
124/******************************************************************************/
125/********************** Public/Extern Declarations ****************************/
126/******************************************************************************/
127extern I2C_HandleTypeDef hi2c1;
128extern SPI_HandleTypeDef hspi1;
129extern DMA_HandleTypeDef hdma_spi1_rx;
130extern TIM_HandleTypeDef htim1;
131extern TIM_HandleTypeDef htim2;
132extern TIM_HandleTypeDef htim8;
133extern DMA_HandleTypeDef hdma_tim1_ch3;
134extern DMA_HandleTypeDef hdma_tim1_ch2;
135extern TIM_HandleTypeDef htim12;
136extern UART_HandleTypeDef huart5;
137extern volatile bool data_ready;
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_cnv_extra_init_params;
142extern struct stm32_gpio_init_param stm32_gpio_gp0_extra_init_params;
143extern struct stm32_gpio_init_param stm32_gpio_gp1_extra_init_params;
144extern struct stm32_gpio_init_param stm32_gpio_reset_extra_init_params;
145extern struct stm32_gpio_irq_init_param stm32_gpio_irq_extra_init_params;
146extern struct stm32_gpio_init_param stm32_pwm_gpio_extra_init_params;
147extern struct stm32_pwm_init_param stm32_pwm_cnv_extra_init_params;
148#if (INTERFACE_MODE == SPI_DMA)
149extern struct stm32_pwm_init_param stm32_cs_extra_init_params;
150extern struct stm32_pwm_init_param stm32_tx_trigger_extra_init_params;
151extern DMA_HandleTypeDef hdma_tim8_ch1;
152extern struct stm32_dma_channel rxdma_channel;
153extern struct stm32_dma_channel txdma_channel;
154extern struct stm32_gpio_init_param stm32_cs_pwm_gpio_extra_init_params;
155extern uint32_t rxdma_ndtr;
156extern uint32_t dma_cycle_count;
157extern USBD_HandleTypeDef hUsbDeviceHS;
159
160void receivecomplete_callback(DMA_HandleTypeDef* hdma);
161void halfcmplt_callback(DMA_HandleTypeDef* hdma);
162void update_buff(uint32_t* local_buf, uint32_t* buf_start_addr);
163void stm32_cnv_output_gpio_config(bool is_gpio);
164void stm32_cs_output_gpio_config(bool is_gpio);
165void stm32_abort_dma_transfer(void);
166void stm32_timer_enable(void);
167void stm32_timer_stop(void);
168#endif
169
170void stm32_system_init(void);
172
173#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
void stm32_system_init(void)
Initialize the STM32 system peripherals.
Definition app_config_stm32.c:176
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_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
SPI_HandleTypeDef hspi1
TIM_HandleTypeDef htim12
volatile int dma_cycle_count
Definition app_config_stm32.c:242
volatile bool data_ready
Definition ad405x_iio.c:137
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_gpio_cnv_extra_init_params
Definition app_config_stm32.c:64
struct stm32_pwm_init_param stm32_pwm_cnv_extra_init_params
Definition app_config_stm32.c:190
struct stm32_gpio_init_param stm32_pwm_gpio_extra_init_params
Definition app_config_stm32.c:180
struct stm32_uart_init_param stm32_uart_extra_init_params
Definition app_config_stm32.c:102
struct stm32_gpio_irq_init_param stm32_gpio_irq_extra_init_params
Definition app_config_stm32.c:156
struct stm32_gpio_init_param stm32_cs_pwm_gpio_extra_init_params
Definition app_config_stm32.c:167
I2C_HandleTypeDef hi2c1
struct stm32_gpio_init_param stm32_gpio_gp0_extra_init_params
Definition app_config_stm32.c:144
struct stm32_gpio_init_param stm32_gpio_gp1_extra_init_params
Definition app_config_stm32.c:150
uint8_t local_buf[MAX_LOCAL_BUF_SIZE]
Definition ad405x_support.c:42
struct stm32_spi_init_param stm32_spi_extra_init_params
Definition app_config_stm32.c:46
struct stm32_dma_channel txdma_channel
Definition app_config_stm32.c:115
void MX_USB_DEVICE_Init(void)
DMA_HandleTypeDef hdma_tim1_ch2
TIM_HandleTypeDef htim1
TIM_HandleTypeDef htim2
TIM_HandleTypeDef htim8
DMA_HandleTypeDef hdma_tim1_ch3
void stm32_cnv_output_gpio_config(bool is_gpio)
Configures the conversion pin as output mode.
Definition app_config_stm32.c:330
struct stm32_gpio_init_param stm32_gpio_reset_extra_init_params
Definition app_config_stm32.c:82
VCOM driver for stm32 as a no_os_uart implementation.
Specific initialization parameters for stm32 UART over USB.
Definition stm32_usb_uart.h:27