Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Examples)!: Require DMA Channel as Input Argument for ADC DMA Conversions, Fix ADC DMA Transfer Bug for Channels > 0 #643

Merged
merged 9 commits into from
Jul 11, 2023
9 changes: 5 additions & 4 deletions Documentation/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,11 @@ The `Documentation/build.py` script can be used to build the MSDK User Guide and
To **build** the docs:

1. Install [doxygen](https://www.doxygen.nl/download.html)
2. Install Python 3
3. `pip install -r Documentation/requirements.txt`
4. `python Documentation/build.py`
5. The site will be built in the `docs` folder of the repo.
2. Add doxygen's binary diretory to the [Environmental Path](https://learn.microsoft.com/en-us/previous-versions/office/developer/sharepoint-2010/ee537574(v=office.14)) Variable
3. Install Python 3
4. `pip install -r Documentation/requirements.txt`
5. `python Documentation/build.py`
6. The site will be built in the `docs` folder of the repo.

To **preview** the generated site:

Expand Down
11 changes: 8 additions & 3 deletions Examples/MAX32662/ADC/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void adc_dma_callback(int ch, int err)
dma_done = 1;
}

void DMA0_IRQHandler(void)
void DMA_IRQHandler(void)
{
MXC_DMA_Handler();
}
Expand Down Expand Up @@ -335,7 +335,6 @@ int main(void)

#ifdef DMA
MXC_DMA_Init();
NVIC_EnableIRQ(DMA0_IRQn);
#endif
while (1) {
/* Flash LED when starting ADC cycle */
Expand All @@ -360,10 +359,16 @@ int main(void)
#ifdef DMA
dma_done = 0;

MXC_DMA_ReleaseChannel(0);
int dma_channel = MXC_DMA_AcquireChannel();
adc_conv.dma_channel = dma_channel;

MXC_NVIC_SetVector(MXC_DMA_CH_GET_IRQ(dma_channel), DMA_IRQHandler);
NVIC_EnableIRQ(MXC_DMA_CH_GET_IRQ(dma_channel));
MXC_ADC_StartConversionDMA(&adc_conv, adc_val, adc_dma_callback);

while (!dma_done) {}

MXC_DMA_ReleaseChannel(adc_conv.dma_channel);
#endif

ShowAdcResult();
Expand Down
12 changes: 8 additions & 4 deletions Examples/MAX32672/ADC/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void adc_dma_callback(int ch, int err)
dma_done = 1;
}

void DMA0_IRQHandler(void)
void DMA_IRQHandler(void)
{
MXC_DMA_Handler();
}
Expand Down Expand Up @@ -375,15 +375,13 @@ int main(void)

#ifdef DMA
MXC_DMA_Init();
NVIC_EnableIRQ(DMA0_IRQn);
#endif

while (1) {
/* Flash LED when starting ADC cycle */
LED_On(0);
MXC_TMR_Delay(MXC_TMR0, MSEC(10));
LED_Off(0);

#ifdef POLLING
adc_temp_conversion();
WaitforConversionComplete();
Expand Down Expand Up @@ -414,10 +412,16 @@ int main(void)
MXC_TMR_Delay(MXC_TMR0, USEC(500));
}

MXC_DMA_ReleaseChannel(0);
int dma_channel = MXC_DMA_AcquireChannel();
adc_conv.dma_channel = dma_channel;

MXC_NVIC_SetVector(MXC_DMA_CH_GET_IRQ(dma_channel), DMA_IRQHandler);
NVIC_EnableIRQ(MXC_DMA_CH_GET_IRQ(dma_channel));
MXC_ADC_StartConversionDMA(&adc_conv, &adc_val[0], adc_dma_callback);

while (!dma_done) {}

MXC_DMA_ReleaseChannel(adc_conv.dma_channel);
#endif
ShowAdcResult();

Expand Down
11 changes: 8 additions & 3 deletions Examples/MAX32690/ADC/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void adc_dma_callback(int ch, int err)
dma_done = 1;
}

void DMA0_IRQHandler(void)
void DMA_IRQHandler(void)
{
MXC_DMA_Handler();
}
Expand Down Expand Up @@ -416,7 +416,6 @@ int main(void)

#ifdef DMA
MXC_DMA_Init();
NVIC_EnableIRQ(DMA0_IRQn);
#endif
while (1) {
/* Flash LED when starting ADC cycle */
Expand Down Expand Up @@ -454,10 +453,16 @@ int main(void)
MXC_TMR_Delay(MXC_TMR0, USEC(500));
}

MXC_DMA_ReleaseChannel(0);
int dma_channel = MXC_DMA_AcquireChannel();
adc_conv.dma_channel = dma_channel;

MXC_NVIC_SetVector(MXC_DMA_CH_GET_IRQ(dma_channel), DMA_IRQHandler);
NVIC_EnableIRQ(MXC_DMA_CH_GET_IRQ(dma_channel));
MXC_ADC_StartConversionDMA(&adc_conv, &adc_val[0], adc_dma_callback);

while (!dma_done) {}

MXC_DMA_ReleaseChannel(adc_conv.dma_channel);
#endif
ShowAdcResult();

Expand Down
13 changes: 9 additions & 4 deletions Examples/MAX78002/ADC/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void adc_dma_callback(int ch, int err)
dma_done = 1;
}

void DMA0_IRQHandler(void)
void DMA_IRQHandler(void)
{
MXC_DMA_Handler();
}
Expand Down Expand Up @@ -385,7 +385,6 @@ int main(void)

#ifdef DMA
MXC_DMA_Init();
NVIC_EnableIRQ(DMA0_IRQn);
#endif
while (1) {
/* Flash LED when starting ADC cycle */
Expand Down Expand Up @@ -423,10 +422,16 @@ int main(void)
MXC_TMR_Delay(MXC_TMR0, USEC(500));
}

MXC_DMA_ReleaseChannel(0);
MXC_ADC_StartConversionDMA(&adc_conv, &adc_val[0], adc_dma_callback);
int dma_channel = MXC_DMA_AcquireChannel();
adc_conv.dma_channel = dma_channel;

MXC_NVIC_SetVector(MXC_DMA_CH_GET_IRQ(dma_channel), DMA_IRQHandler);
NVIC_EnableIRQ(MXC_DMA_CH_GET_IRQ(dma_channel));
MXC_ADC_StartConversionDMA(&adc_conv, adc_val, adc_dma_callback);

while (!dma_done) {}

MXC_DMA_ReleaseChannel(adc_conv.dma_channel);
#endif
ShowAdcResult();

Expand Down
7 changes: 7 additions & 0 deletions Libraries/CMSIS/Device/Maxim/MAX32662/Include/max32662.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,13 @@ typedef enum {

#define MXC_DMA_GET_IDX(p) ((p) == MXC_DMA ? 0 : -1)

#define MXC_DMA_CH_GET_IRQ(i) \
((IRQn_Type)(((i) == 0) ? DMA0_IRQn : \
((i) == 1) ? DMA1_IRQn : \
((i) == 2) ? DMA2_IRQn : \
((i) == 3) ? DMA3_IRQn : \
0))

/******************************************************************************/
/* FLC */
#define MXC_FLC_INSTANCES (1)
Expand Down
15 changes: 15 additions & 0 deletions Libraries/CMSIS/Device/Maxim/MAX32672/Include/max32672.h
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,21 @@ mxc_aes_regs_t mxc_sys_aes_regs_t;

#define MXC_DMA_GET_IDX(p) ((p) == MXC_DMA ? 0 : -1)

#define MXC_DMA_CH_GET_IRQ(i) \
((IRQn_Type)(((i) == 0) ? DMA0_IRQn : \
((i) == 1) ? DMA1_IRQn : \
((i) == 2) ? DMA2_IRQn : \
((i) == 3) ? DMA3_IRQn : \
((i) == 4) ? DMA4_IRQn : \
((i) == 5) ? DMA5_IRQn : \
((i) == 6) ? DMA6_IRQn : \
((i) == 7) ? DMA7_IRQn : \
((i) == 8) ? DMA8_IRQn : \
((i) == 9) ? DMA9_IRQn : \
((i) == 10) ? DMA10_IRQn : \
((i) == 11) ? DMA11_IRQn : \
0))

/******************************************************************************/
/* FLC */
#define MXC_FLC_INSTANCES (2)
Expand Down
19 changes: 19 additions & 0 deletions Libraries/CMSIS/Device/Maxim/MAX32690/Include/max32690.h
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,25 @@ typedef enum {

#define MXC_DMA_GET_IDX(p) ((p) == MXC_DMA ? 0 : -1)

#define MXC_DMA_CH_GET_IRQ(i) \
((IRQn_Type)(((i) == 0) ? DMA0_IRQn : \
((i) == 1) ? DMA1_IRQn : \
((i) == 2) ? DMA2_IRQn : \
((i) == 3) ? DMA3_IRQn : \
((i) == 4) ? DMA4_IRQn : \
((i) == 5) ? DMA5_IRQn : \
((i) == 6) ? DMA6_IRQn : \
((i) == 7) ? DMA7_IRQn : \
((i) == 8) ? DMA8_IRQn : \
((i) == 9) ? DMA9_IRQn : \
((i) == 10) ? DMA10_IRQn : \
((i) == 11) ? DMA11_IRQn : \
((i) == 12) ? DMA12_IRQn : \
((i) == 13) ? DMA13_IRQn : \
((i) == 14) ? DMA14_IRQn : \
((i) == 15) ? DMA15_IRQn : \
0))

/******************************************************************************/
/* FLC */
#define MXC_FLC_INSTANCES (2)
Expand Down
17 changes: 16 additions & 1 deletion Libraries/PeriphDrivers/Include/MAX32662/adc.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ extern "C" {
/**
* @defgroup adc ADC
* @ingroup periphlibs
* @details API for Analog to Digital Converter (ADC).
* @{
*/

Expand Down Expand Up @@ -180,6 +181,9 @@ typedef enum {
///< Callback used when a conversion event is complete
typedef void (*mxc_adc_complete_cb_t)(void *req, int error);

/**
* @brief ADC Settings
*/
typedef struct {
mxc_adc_clock_t clock; ///< clock to use
mxc_adc_clkdiv_t clkdiv; ///< clock divider
Expand All @@ -189,10 +193,16 @@ typedef struct {
uint32_t idleCount; ///< Sample Clock Low time
} mxc_adc_req_t;

/**
* @brief ADC Slot Settings
*/
typedef struct {
mxc_adc_chsel_t channel; ///< channel select
} mxc_adc_slot_req_t;

/**
* @brief ADC Conversion Settings
*/
typedef struct {
mxc_adc_conversion_mode_t mode; ///< conversion mode
mxc_adc_trig_mode_t trig; ///< trigger mode
Expand All @@ -202,6 +212,7 @@ typedef struct {
mxc_adc_avg_t avg_number; ///< no of samples to average
mxc_adc_div_lpmode_t lpmode_divder; ///< Divide by 2 control in lpmode
uint8_t num_slots; ///< num of slots in the sequence
int8_t dma_channel; ///<The channel to use for DMA-enabled transactions
} mxc_adc_conversion_req_t;

/**
Expand Down Expand Up @@ -267,7 +278,11 @@ int MXC_ADC_StartConversion(void);
int MXC_ADC_StartConversionAsync(mxc_adc_complete_cb_t callback);

/**
* @brief Perform a conversion on a specific channel using a DMA transfer
* @brief Perform a conversion on a specific channel using a DMA transfer.
* DMA channel must be acquired using \ref MXC_DMA_AcquireChannel and should
* be passed to this function via "dma_channel" member of "req" input struct.
* DMA IRQ corresponding to that channel must be enabled using \ref MXC_NVIC_SetVector,
* and the \ref MXC_DMA_Handler should be called from the respective ISR.
*
* @param req \ref mxc_adc_conversion_req_t
* @param pointer to the variable to hold the conversion result
Expand Down
19 changes: 17 additions & 2 deletions Libraries/PeriphDrivers/Include/MAX32672/adc.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ extern "C" {
/**
* @defgroup adc ADC
* @ingroup periphlibs
* @details API for Analog to Digital Converter (ADC).
* @{
*/

Expand Down Expand Up @@ -222,6 +223,9 @@ typedef enum {
///< Callback used when a conversion event is complete
typedef void (*mxc_adc_complete_cb_t)(void *req, int error);

/**
* @brief ADC Settings
*/
typedef struct {
mxc_adc_clock_t clock; ///< clock to use
mxc_adc_clkdiv_t clkdiv; ///< clock divider
Expand All @@ -231,12 +235,18 @@ typedef struct {
uint32_t idleCount; ///< Sample Clock Low time
} mxc_adc_req_t;

/**
* @brief ADC Slot Settings
*/
typedef struct {
mxc_adc_chsel_t channel; ///< channel select
mxc_adc_divsel_t div; ///< Analog input divider
mxc_adc_dynamic_pullup_t pullup_dyn; ///< Dynamic Pullup
} mxc_adc_slot_req_t;

/**
* @brief ADC Conversion Settings
*/
typedef struct {
mxc_adc_conversion_mode_t mode; ///< conversion mode
mxc_adc_trig_mode_t trig; ///< trigger mode
Expand All @@ -246,6 +256,7 @@ typedef struct {
mxc_adc_avg_t avg_number; ///< no of samples to average
mxc_adc_div_lpmode_t lpmode_divder; ///< Divide by 2 control in lpmode
uint8_t num_slots; ///< num of slots in the sequence
int8_t dma_channel; ///<The channel to use for DMA-enabled transactions
} mxc_adc_conversion_req_t;

/**
Expand Down Expand Up @@ -311,8 +322,12 @@ int MXC_ADC_StartConversion(void);
int MXC_ADC_StartConversionAsync(mxc_adc_complete_cb_t callback);

/**
* @brief Perform a conversion on a specific channel using a DMA transfer
*
* @brief Perform a conversion on a specific channel using a DMA transfer.
* DMA channel must be acquired using \ref MXC_DMA_AcquireChannel and should
* be passed to this function via "dma_channel" member of "req" input struct.
* DMA IRQ corresponding to that channel must be enabled using \ref MXC_NVIC_SetVector,
* and the \ref MXC_DMA_Handler should be called from the respective ISR.
*
* @param req \ref mxc_adc_conversion_req_t
* @param pointer to the variable to hold the conversion result
* @param callback the function to call when the conversion is complete
Expand Down
Loading