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_gpio_irq.h"
27 #include "app_config.h"
28 
29 /******************************************************************************/
30 /********************** Macros and Constants Definition ***********************/
31 /******************************************************************************/
32 
33 /* Note: The SDP-K1 board with the STM32F469NI MCU has been used
34 * for developing the firmware. The below parameters will change depending
35 * on the controller used. */
36 #define HW_CARRIER_NAME SDP_K1
37 
38 /* STM32 UART specific parameters */
39 #define APP_UART_HANDLE &huart5
40 #define UART_IRQ_ID UART5_IRQn
41 
42 /* GPIO Pins associated with DAC */
43 #define RESET_PIN 11 // PG11
44 #define RESET_PORT 6 // PORTG
45 #define LDAC_PIN 15 // PB15
46 #define LDAC_PORT 1 // PORTB
47 #define GPIO_TRIGGER_INT_PORT 1 //PORTB
48 #define SPI_DMA_TX_STOP_PWM_GPIO_PIN 12 //PD12
49 #define SPI_DMA_TX_STOP_PWM_GPIO_PORT 3 //PORTD
50 
51 /* STM32 SPI Specific parameters */
52 #define SPI_DEVICE_ID 1 //SPI1
53 #define SPI_CSB 15 //PA15
54 #define STM32_SPI_CS_PORT 0 //PORTA
55 
56 /* Interrupt Callback parameters */
57 #define IRQ_CTRL_ID 15 // PB15
58 #define TRIGGER_INT_ID 15 // PB15
59 #define trigger_gpio_handle 0
60 #define LDAC_GPIO_PRIORITY 1
61 
62 /* STM32 LDAC PWM Specific parameters */
63 #define LDAC_PWM_ID 12 //Timer12
64 #define LDAC_PWM_CHANNEL 2 // Channel 2
65 #define LDAC_PWM_CLK_DIVIDER 2 // multiplier to get timer clock from PLCK1
66 
67 /* STM32 PWM specific parameters to stop spi dma transfer */
68 #define SPI_DMA_TX_STOP_PWM_ID 4 //Timer4
69 #define SPI_DMA_TX_STOP_PWM_PRESCALER 0
70 #define SPI_DMA_TX_STOP_PWM_CHANNEL 1 // Channel 1
71 #define SPI_DMA_TX_STOP_PWM_CLK_DIVIDER 2 // multiplier to get timer clock from PLCK1
72 
73 /* Redefine the init params structure mapping wrt platform */
74 #define spi_extra_init_params stm32_spi_init_params
75 #define spi_extra_init_params_without_sw_csb stm32_spi_init_params_without_sw_csb
76 #define uart_extra_init_params stm32_uart_init_params
77 #define ldac_pwm_extra_init_params stm32_ldac_pwm_init_params
78 #define spi_dma_tx_stop_pwm_extra_init_params stm32_spi_dma_tx_stop_pwm_init_params
79 #define gpio_ldac_extra_init_params stm32_gpio_ldac_init_params
80 #define spi_dma_tx_stop_pwm_gpio_extra_init_params stm32_spi_dma_tx_stop_pwm_gpio_init_params
81 #define gpio_reset_extra_init_params stm32_gpio_reset_init_params
82 #define ext_int_extra_init_params stm32_trigger_gpio_irq_init_params
83 
84 /* Platform Ops */
85 #define irq_platform_ops stm32_gpio_irq_ops
86 #define gpio_ops stm32_gpio_ops
87 #define spi_ops stm32_spi_ops
88 #define pwm_ops stm32_pwm_ops
89 #define uart_ops stm32_uart_ops
90 
91 /* Define the max possible sampling rate for a given platform.
92  * Note: This is derived by testing the firmware on SDP-K1 controller
93  * board with STM32F469NI MCU.
94  * The max possible sampling rate can vary from board to board */
95 #if (INTERFACE_MODE == SPI_DMA)
96 #define MAX_SAMPLING_RATE 274423
97 #define LDAC_PWM_DUTY_CYCLE 99
98 #define MAX_SPI_SCLK 11250000
99 #define LDAC_PWM_PRESCALER 0
100 #define SPI_DMA_TX_STOP_PWM_DUTY_CYCLE 50
101 #else
102 #define MAX_SAMPLING_RATE 21593
103 #define LDAC_PWM_DUTY_CYCLE 50
104 #define MAX_SPI_SCLK 22500000
105 #define LDAC_PWM_PRESCALER 3
106 #endif
107 
108 /******************************************************************************/
109 /********************** Variables and User Defined Data Types *****************/
110 /******************************************************************************/
111 extern struct stm32_uart_init_param stm32_uart_init_params;
112 extern struct stm32_gpio_irq_init_param stm32_trigger_gpio_irq_init_params;
113 extern struct stm32_spi_init_param stm32_spi_init_params;
114 extern struct stm32_spi_init_param stm32_spi_init_params_without_sw_csb;
115 extern struct stm32_gpio_init_param stm32_gpio_ldac_init_params;
116 extern struct stm32_gpio_init_param
118 extern struct stm32_gpio_init_param stm32_gpio_reset_init_params;
119 extern struct stm32_pwm_init_param stm32_ldac_pwm_init_params;
120 extern struct stm32_pwm_init_param stm32_spi_dma_tx_stop_pwm_init_params;
121 extern UART_HandleTypeDef huart5;
122 extern SPI_HandleTypeDef hspi1;
123 extern TIM_HandleTypeDef htim4;
125 
126 int32_t stm32_spi_dma_enable(struct stm32_spi_desc* spidesc,
127  struct iio_device_data* iio_dev_data, uint16_t num_of_bytes_transfer,
128  uint8_t start_addr);
129 int32_t stm32_spi_dma_disable(struct stm32_spi_desc* spidesc);
130 #endif // APP_CONFIG_STM32_H_
#define NUMBER_OF_CHANNELS
Definition: app_config.h:83
struct stm32_pwm_init_param stm32_spi_dma_tx_stop_pwm_init_params
Definition: app_config_stm32.c:82
UART_HandleTypeDef huart5
struct stm32_gpio_init_param stm32_gpio_ldac_init_params
Definition: app_config_stm32.c:52
struct stm32_pwm_init_param stm32_ldac_pwm_init_params
Definition: app_config_stm32.c:72
struct stm32_spi_init_param stm32_spi_init_params
Definition: app_config_stm32.c:40
struct stm32_spi_init_param stm32_spi_init_params_without_sw_csb
Definition: app_config_stm32.c:46
uint32_t spi_dma_tx_stop_pwm_frquency[NUMBER_OF_CHANNELS]
Definition: app_config_stm32.h:124
int32_t stm32_spi_dma_enable(struct stm32_spi_desc *spidesc, struct iio_device_data *iio_dev_data, uint16_t num_of_bytes_transfer, uint8_t start_addr)
Enables SPI DMA to move data from iio buffer to SPI TX buffer.
Definition: app_config_stm32.c:175
TIM_HandleTypeDef htim4
SPI_HandleTypeDef hspi1
struct stm32_gpio_init_param stm32_gpio_reset_init_params
Definition: app_config_stm32.c:67
int32_t stm32_spi_dma_disable(struct stm32_spi_desc *spidesc)
Disable SPI DMA which move data from iio buffer to SPI TX buffer.
Definition: app_config_stm32.c:223
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_gpio_init_param stm32_spi_dma_tx_stop_pwm_gpio_init_params
Definition: app_config_stm32.c:60
Configuration file of nanodac firmware example program.