Skip to content

Commit

Permalink
projects:ad405x_iio: Update DMA implementation in continuous capture …
Browse files Browse the repository at this point in the history
…mode

Signed-off-by: Anush Shetty <anush.shetty@analog.com>
  • Loading branch information
Shetty-Anush authored and jansunil committed Jan 10, 2025
1 parent f88cc82 commit 13e5d30
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
3 changes: 2 additions & 1 deletion projects/ad405x_iio/STM32/ad405x_iio.ioc
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,9 @@ UART5.BaudRate=230400
UART5.IPParameters=VirtualMode,BaudRate
UART5.VirtualMode=Asynchronous
USB_DEVICE.CLASS_NAME_HS=CDC
USB_DEVICE.IPParameters=VirtualMode-CDC_HS,VirtualModeHS,CLASS_NAME_HS,VID-CDC_HS,PID_CDC_HS
USB_DEVICE.IPParameters=VirtualMode-CDC_HS,VirtualModeHS,CLASS_NAME_HS,VID-CDC_HS,PID_CDC_HS,PRODUCT_STRING_CDC_HS
USB_DEVICE.PID_CDC_HS=0xB66C
USB_DEVICE.PRODUCT_STRING_CDC_HS=STM32_Virtual_COM_Port
USB_DEVICE.VID-CDC_HS=0x0456
USB_DEVICE.VirtualMode-CDC_HS=Cdc
USB_DEVICE.VirtualModeHS=Cdc_HS
Expand Down
30 changes: 12 additions & 18 deletions projects/ad405x_iio/app/ad405x_iio.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ static struct iio_attribute ad405x_debug_attributes[] = {
volatile struct iio_device_data* iio_dev_data_g;

/* Global variable for number of samples */
uint32_t nb_of_samples_g;
uint32_t nb_of_bytes_g;

/* Global variable for data read from CB functions */
int32_t data_read;
Expand Down Expand Up @@ -935,7 +935,6 @@ int32_t ad405x_stop_data_capture(void)
if (ret) {
return ret;
}
#endif

#if (APP_CAPTURE_MODE == CONTINUOUS_DATA_CAPTURE)
ret = iio_trig_disable(ad405x_hw_trig_desc);
Expand All @@ -948,6 +947,7 @@ int32_t ad405x_stop_data_capture(void)
return ret;
}
#endif
#endif

#if (INTERFACE_MODE == SPI_DMA)
/* Abort DMA and Timers and configure CS and CNV as GPIOs */
Expand Down Expand Up @@ -987,7 +987,7 @@ static int32_t iio_ad405x_prepare_transfer(void *dev, uint32_t mask)
{
int ret;

#if (APP_CAPTURE_MODE == CONTINUOUS_DATA_CAPTURE)
#if (APP_CAPTURE_MODE == CONTINUOUS_DATA_CAPTURE) && (INTERFACE_MODE == SPI_INTERRUPT)
return ad405x_start_data_capture();
#endif

Expand Down Expand Up @@ -1072,7 +1072,7 @@ static int32_t iio_ad405x_submit_samples(struct iio_device_data *iio_dev_data)
uint16_t spirxdma_ndtr;

nb_of_samples = iio_dev_data->buffer->size / BYTES_PER_SAMPLE;
nb_of_samples_g = nb_of_samples;
nb_of_bytes_g = nb_of_samples * BYTES_PER_SAMPLE;
iio_dev_data_g = iio_dev_data;

if (!buf_size_updated) {
Expand Down Expand Up @@ -1179,7 +1179,6 @@ static int32_t iio_ad405x_submit_samples(struct iio_device_data *iio_dev_data)

no_os_cb_end_async_write(iio_dev_data->buffer->buf);
#else

if (!dma_config_updated) {
ret = no_os_cb_prepare_async_write(iio_dev_data->buffer->buf,
nb_of_samples * (BYTES_PER_SAMPLE),
Expand All @@ -1192,7 +1191,7 @@ static int32_t iio_ad405x_submit_samples(struct iio_device_data *iio_dev_data)
struct no_os_spi_msg ad405x_spi_msg = {
.tx_buff = (uint32_t*)local_tx_data,
.rx_buff = (uint32_t*)buff_start_addr,
.bytes_number = nb_of_samples * (BYTES_PER_SAMPLE)
.bytes_number = spirxdma_ndtr
};

ret = no_os_spi_transfer_dma_async(p_ad405x_dev->spi_desc,
Expand All @@ -1207,8 +1206,9 @@ static int32_t iio_ad405x_submit_samples(struct iio_device_data *iio_dev_data)
no_os_pwm_disable(sdesc->pwm_desc); // CS PWM
htim2.Instance->CNT = 0;
htim1.Instance->CNT = 0;
TIM8->CNT = 0;
dma_config_updated = true;
tim8_config();

stm32_timer_enable();
}

Expand Down Expand Up @@ -1237,7 +1237,6 @@ static int32_t ad405x_trigger_handler(struct iio_device_data *iio_dev_data)
buf_size_updated = true;
}

#if (INTERFACE_MODE == SPI_INTERRUPT)
#if (ADC_CAPTURE_MODE == AVERAGING_MODE)
cnv_count += 1;
if (cnv_count < (1 << (1 + p_ad405x_dev->filter_length))) {
Expand All @@ -1256,11 +1255,6 @@ static int32_t ad405x_trigger_handler(struct iio_device_data *iio_dev_data)
#endif

return no_os_cb_write(iio_dev_data->buffer->buf, &data_read, BYTES_PER_SAMPLE);
#else
no_os_cb_prepare_async_write(iio_dev_data->buffer->buf,
nb_of_samples * (BYTES_PER_SAMPLE), &buff_start_addr, &data_read);
no_os_cb_end_async_write(iio_dev_data->buffer->buf);
#endif
}

/*!
Expand Down Expand Up @@ -1468,7 +1462,7 @@ int32_t iio_ad405x_initialize(void)
enum ad405x_device_type dev_type;
uint8_t indx;

#if (APP_CAPTURE_MODE == CONTINUOUS_DATA_CAPTURE)
#if (APP_CAPTURE_MODE == CONTINUOUS_DATA_CAPTURE) && (INTERFACE_MODE == SPI_INTERRUPT)
static struct iio_trigger ad405x_iio_trig_desc = {
.is_synchronous = true,
.enable = NULL,
Expand All @@ -1484,15 +1478,15 @@ int32_t iio_ad405x_initialize(void)
/* IIO interface init parameters */
struct iio_init_param iio_init_params = {
.phy_type = USE_UART,
#if (APP_CAPTURE_MODE == CONTINUOUS_DATA_CAPTURE)
#if (APP_CAPTURE_MODE == CONTINUOUS_DATA_CAPTURE) && (INTERFACE_MODE == SPI_INTERRUPT)
.trigs = &iio_trigger_init_params,
#endif
};

/* IIOD init parameters */
static struct iio_device_init iio_device_init_params[NUM_OF_IIO_DEVICES] = {
{
#if (APP_CAPTURE_MODE == CONTINUOUS_DATA_CAPTURE)
#if (APP_CAPTURE_MODE == CONTINUOUS_DATA_CAPTURE) && (INTERFACE_MODE == SPI_INTERRUPT)
.trigger_id = "trigger0",
#endif
}
Expand Down Expand Up @@ -1568,7 +1562,7 @@ int32_t iio_ad405x_initialize(void)

iio_init_params.nb_devs++;

#if (APP_CAPTURE_MODE == CONTINUOUS_DATA_CAPTURE)
#if (APP_CAPTURE_MODE == CONTINUOUS_DATA_CAPTURE) && (INTERFACE_MODE == SPI_INTERRUPT)
iio_init_params.nb_trigs++;
#endif
}
Expand All @@ -1581,7 +1575,7 @@ int32_t iio_ad405x_initialize(void)
return init_status;
}

#if (APP_CAPTURE_MODE == CONTINUOUS_DATA_CAPTURE)
#if (APP_CAPTURE_MODE == CONTINUOUS_DATA_CAPTURE) && (INTERFACE_MODE == SPI_INTERRUPT)
init_status = ad405x_iio_trigger_param_init(&ad405x_hw_trig_desc);
if (init_status) {
return init_status;
Expand Down
6 changes: 3 additions & 3 deletions projects/ad405x_iio/app/app_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
#define ACTIVE_PLATFORM STM32_PLATFORM
#endif

/* Enable the UART/VirtualCOM port connection */
#define USE_PHY_COM_PORT // Uncomment to select UART
/* Enable the UART/VirtualCOM port connection (default VCOM) */
//#define USE_PHY_COM_PORT // Uncomment to select UART

#if !defined(USE_PHY_COM_PORT)
#define USE_VIRTUAL_COM_PORT
Expand Down Expand Up @@ -181,7 +181,7 @@ extern struct no_os_gpio_init_param cs_pwm_gpio_params;
extern struct no_os_gpio_init_param pwm_gpio_params;
extern volatile uint32_t* buff_start_addr;
extern volatile struct iio_device_data* iio_dev_data_g;
extern uint32_t nb_of_samples_g;
extern uint32_t nb_of_bytes_g;
extern int32_t data_read;
extern struct no_os_pwm_desc* tx_trigger_desc;
#endif
Expand Down
12 changes: 11 additions & 1 deletion projects/ad405x_iio/app/app_config_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "app_config_stm32.h"
#include "ad405x_iio.h"
#include "ad405x.h"
#include "iio.h"

/******************************************************************************/
/************************ Macros/Constants ************************************/
/******************************************************************************/
Expand Down Expand Up @@ -246,7 +248,7 @@ void stm32_system_init(void)
*/
void DMA2_Stream0_IRQHandler(void)
{
#if (DATA_CAPTURE_MODE == BURST_DATA_CAPTURE)
#if (APP_CAPTURE_MODE == WINDOWED_DATA_CAPTURE)
/* Stop timers at the last entry to the callback */
if (callback_count == 1) {
sdesc = p_ad405x_dev->spi_desc->extra;
Expand Down Expand Up @@ -344,6 +346,7 @@ void stm32_timer_stop(void)

void receivecomplete_callback(DMA_HandleTypeDef * hdma)
{
#if (APP_CAPTURE_MODE == WINDOWED_DATA_CAPTURE)
if (!dma_cycle_count) {
return;
}
Expand Down Expand Up @@ -374,6 +377,13 @@ void receivecomplete_callback(DMA_HandleTypeDef * hdma)
}

return;
#else
no_os_cb_end_async_write(iio_dev_data_g->buffer->buf);
no_os_cb_prepare_async_write(iio_dev_data_g->buffer->buf,
nb_of_bytes_g,
&buff_start_addr,
&data_read);
#endif
}

/**
Expand Down

0 comments on commit 13e5d30

Please sign in to comment.