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(PeriphDrivers): Fix UART DMA Transactions and Enable Full Duplex #763

Merged
merged 28 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b6d919d
Fix DMA channel leak in UART RevA
Jake-Carter Oct 9, 2023
b9393ea
Add MXC_DMA_CH_GET_IRQ for ME14
Jake-Carter Oct 9, 2023
34276b4
Checkpoint: auto interrupt handlers (not totally compatible with old …
Jake-Carter Oct 9, 2023
77ecaef
UART_RevA: Add APIs for setting DMA handlers, expose to ME14
Jake-Carter Oct 10, 2023
e2a9134
clang-format
Jake-Carter Oct 10, 2023
bd4e60f
Implement autohandlers for UART Rev B
Jake-Carter Oct 16, 2023
fade8a5
Add function prototypes for all micros
Jake-Carter Oct 20, 2023
1a336ea
Add RevB passthroughs
Jake-Carter Oct 20, 2023
2d325eb
Add stdbool to all uart.h
Jake-Carter Oct 20, 2023
07eef60
Add RevA passthroughs
Jake-Carter Oct 20, 2023
2d5ec93
Fix req clobbering and callbacks for RevA
Jake-Carter Oct 20, 2023
a03f22b
Fix req clobbering and callbacks for RevB
Jake-Carter Oct 20, 2023
2cd7d4f
Fix build error
Jake-Carter Oct 20, 2023
d9e9441
clang-format
Jake-Carter Oct 20, 2023
fe51c36
Add newline at end of file
Jake-Carter Oct 23, 2023
dc04d78
Fix -1 assigned to uint8_t
Jake-Carter Oct 23, 2023
2ea9524
clang-format bot reformatting.
EricB-ADI Oct 24, 2023
aba737e
Remove UART FIFO clears in me21 file
Jake-Carter Oct 25, 2023
831c893
Address Lorne review notes
Jake-Carter Nov 13, 2023
8086917
Only acquire channel if we don't have one already
Jake-Carter Nov 13, 2023
ad19c87
Update UART example projects
Jake-Carter Nov 14, 2023
34db845
Use MXC_ASSERT instead of runtime checks
Jake-Carter Nov 29, 2023
81837cc
Disable MXC_ASSERT for bootloader examples
Jake-Carter Nov 29, 2023
c24e810
Merge remote-tracking branch 'remotes/upstream/main' into fix/gh-761
Jake-Carter Nov 29, 2023
566f057
Fix variable mismatch, swap for more asserts
Jake-Carter Nov 30, 2023
b332e72
Disable MXC_ASSERT for SCPA_OTP_Dump
Jake-Carter Nov 30, 2023
63fca53
clang-format
Jake-Carter Nov 30, 2023
85020c8
PURGE THE ASSERTS
Jake-Carter Nov 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Examples/MAX32655/Bluetooth/Bootloader/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ MXC_OPTIMIZE_CFLAGS ?= -Og

# Set compiler flags
PROJ_CFLAGS += -Wall # Enable warnings
PROJ_CFLAGS += -DMXC_ASSERT_ENABLE
# PROJ_CFLAGS += -DMXC_ASSERT_ENABLE

# Set hardware floating point acceleration.
# Options are:
Expand Down
2 changes: 1 addition & 1 deletion Examples/MAX32662/SCPA_OTP_Dump/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ MXC_OPTIMIZE_CFLAGS ?= -Og

# Set compiler flags
PROJ_CFLAGS += -Wall # Enable warnings
PROJ_CFLAGS += -DMXC_ASSERT_ENABLE
# PROJ_CFLAGS += -DMXC_ASSERT_ENABLE

# Set hardware floating point acceleration.
# Options are:
Expand Down
2 changes: 1 addition & 1 deletion Examples/MAX32665/Bluetooth/Bootloader/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ MXC_OPTIMIZE_CFLAGS ?= -Og

# Set compiler flags
PROJ_CFLAGS += -Wall # Enable warnings
PROJ_CFLAGS += -DMXC_ASSERT_ENABLE
# PROJ_CFLAGS += -DMXC_ASSERT_ENABLE

# Set hardware floating point acceleration.
# Options are:
Expand Down
41 changes: 15 additions & 26 deletions Examples/MAX32672/UART/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,9 @@

/***** Globals *****/
volatile int READ_FLAG;
volatile int DMA_FLAG;

/***** Functions *****/
#ifdef DMA
void DMA_Handler(void)
{
MXC_DMA_Handler();
DMA_FLAG = 0;
}
#else // DMA
#ifndef DMA
void Reading_UART_Handler(void)
{
MXC_UART_AsyncHandler(READING_UART);
Expand Down Expand Up @@ -121,11 +114,7 @@ int main(void)
}
memset(RxData, 0x0, BUFF_SIZE);

#ifdef DMA
MXC_DMA_ReleaseChannel(0);
MXC_NVIC_SetVector(DMA0_IRQn, DMA_Handler);
NVIC_EnableIRQ(DMA0_IRQn);
#else // DMA
#ifndef DMA
NVIC_ClearPendingIRQ(MXC_UART_GET_IRQ(READING_UART_IDX));
NVIC_DisableIRQ(MXC_UART_GET_IRQ(READING_UART_IDX));
MXC_NVIC_SetVector(MXC_UART_GET_IRQ(READING_UART_IDX), Reading_UART_Handler);
Expand All @@ -150,6 +139,12 @@ int main(void)
}
printf("-->Writing UART Initialized\n\n");

#ifdef DMA
// Automatically set up DMA handlers/ISRs
MXC_UART_SetAutoDMAHandlers(READING_UART, true);
MXC_UART_SetAutoDMAHandlers(WRITING_UART, true);
#endif

// Set Parameters for UART transaction requests
mxc_uart_req_t read_req;
read_req.uart = READING_UART;
Expand All @@ -168,16 +163,16 @@ int main(void)
printf("-->Starting transaction\n");

// Initiate Reading UART transaction
READ_FLAG = 1;
MXC_UART_ClearRXFIFO(READING_UART); // Clear any previously pending data
#ifdef DMA
DMA_FLAG = 1;
error = MXC_UART_TransactionDMA(&read_req);
#else // DMA
READ_FLAG = 1;
error = MXC_UART_TransactionAsync(&read_req);
#endif // DMA

if (error != E_NO_ERROR) {
printf("-->Error starting async read: %d\n", error);
printf("-->Error starting read: %d\n", error);
printf("-->Example Failed\n");
return error;
}
Expand All @@ -190,21 +185,15 @@ int main(void)
return error;
}

#ifdef DMA
// Wait for Reading DMA transaction to complete
while (DMA_FLAG) {}
#else // DMA

// Wait for Async Read transaction to complete
// Wait for read transaction to complete
while (READ_FLAG) {}

printf("-->Transaction complete\n\n");

if (READ_FLAG != E_NO_ERROR) {
printf("-->Error with UART_ReadAsync callback; %d\n", READ_FLAG);
printf("-->Error from UART read callback; %d\n", READ_FLAG);
fail++;
}
#endif // DMA

printf("-->Transaction complete\n\n");

// Verify data received matches data transmitted
if ((error = memcmp(RxData, TxData, BUFF_SIZE)) != 0) {
Expand Down
2 changes: 1 addition & 1 deletion Examples/MAX32690/Bluetooth/Bootloader/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ MXC_OPTIMIZE_CFLAGS ?= -Og

# Set compiler flags
PROJ_CFLAGS += -Wall # Enable warnings
PROJ_CFLAGS += -DMXC_ASSERT_ENABLE
# # PROJ_CFLAGS += -DMXC_ASSERT_ENABLE

# Set hardware floating point acceleration.
# Options are:
Expand Down
72 changes: 28 additions & 44 deletions Examples/MAX78000/UART/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,29 +75,22 @@

/***** Globals *****/
volatile int READ_FLAG;
volatile int DMA_FLAG;

#if defined(BOARD_EVKIT_V1)
#define READING_UART 1
#define WRITING_UART 2
#define READING_UART MXC_UART1
#define WRITING_UART MXC_UART2
#elif defined(BOARD_FTHR_REVA)
#define READING_UART 2
#define WRITING_UART 3
#define READING_UART MXC_UART2
#define WRITING_UART MXC_UART3
#else
#warning "This example has been written for the MAX78000 Ev Kit or FTHR board."
#endif

/***** Functions *****/
#ifdef DMA
void DMA_Handler(void)
#ifndef DMA
void Reading_UART_Handler(void)
{
MXC_DMA_Handler();
DMA_FLAG = 0;
}
#else
void UART_Handler(void)
{
MXC_UART_AsyncHandler(MXC_UART_GET_UART(READING_UART));
MXC_UART_AsyncHandler(READING_UART);
}
#endif

Expand Down Expand Up @@ -127,62 +120,58 @@ int main(void)

memset(RxData, 0x0, BUFF_SIZE);

#ifdef DMA
MXC_DMA_Init();
MXC_DMA_ReleaseChannel(0);
MXC_NVIC_SetVector(DMA0_IRQn, DMA_Handler);
NVIC_EnableIRQ(DMA0_IRQn);
#else
NVIC_ClearPendingIRQ(MXC_UART_GET_IRQ(READING_UART));
NVIC_DisableIRQ(MXC_UART_GET_IRQ(READING_UART));
MXC_NVIC_SetVector(MXC_UART_GET_IRQ(READING_UART), UART_Handler);
NVIC_EnableIRQ(MXC_UART_GET_IRQ(READING_UART));
#ifndef DMA
NVIC_ClearPendingIRQ(MXC_UART_GET_IRQ(READING_UART_IDX));
NVIC_DisableIRQ(MXC_UART_GET_IRQ(READING_UART_IDX));
MXC_NVIC_SetVector(MXC_UART_GET_IRQ(READING_UART_IDX), Reading_UART_Handler);
NVIC_EnableIRQ(MXC_UART_GET_IRQ(READING_UART_IDX));
#endif

// Initialize the UART
if ((error = MXC_UART_Init(MXC_UART_GET_UART(READING_UART), UART_BAUD, MXC_UART_APB_CLK)) !=
E_NO_ERROR) {
if ((error = MXC_UART_Init(READING_UART, UART_BAUD, MXC_UART_APB_CLK)) != E_NO_ERROR) {
printf("-->Error initializing UART: %d\n", error);
printf("-->Example Failed\n");
return error;
}

if ((error = MXC_UART_Init(MXC_UART_GET_UART(WRITING_UART), UART_BAUD, MXC_UART_APB_CLK)) !=
E_NO_ERROR) {
if ((error = MXC_UART_Init(WRITING_UART, UART_BAUD, MXC_UART_APB_CLK)) != E_NO_ERROR) {
printf("-->Error initializing UART: %d\n", error);
printf("-->Example Failed\n");
return error;
}

printf("-->UART Initialized\n\n");

#ifdef DMA
// Automatically set up DMA handlers/ISRs
MXC_UART_SetAutoDMAHandlers(READING_UART, true);
MXC_UART_SetAutoDMAHandlers(WRITING_UART, true);
#endif

mxc_uart_req_t read_req;
read_req.uart = MXC_UART_GET_UART(READING_UART);
read_req.uart = READING_UART;
read_req.rxData = RxData;
read_req.rxLen = BUFF_SIZE;
read_req.txLen = 0;
read_req.callback = readCallback;

mxc_uart_req_t write_req;
write_req.uart = MXC_UART_GET_UART(WRITING_UART);
write_req.uart = WRITING_UART;
write_req.txData = TxData;
write_req.txLen = BUFF_SIZE;
write_req.rxLen = 0;
write_req.callback = NULL;

READ_FLAG = 1;
DMA_FLAG = 1;

MXC_UART_ClearRXFIFO(MXC_UART_GET_UART(READING_UART));

MXC_UART_ClearRXFIFO(READING_UART); // Clear any previously pending data
#ifdef DMA
error = MXC_UART_TransactionDMA(&read_req);
#else
error = MXC_UART_TransactionAsync(&read_req);
#endif

if (error != E_NO_ERROR) {
printf("-->Error starting async read: %d\n", error);
printf("-->Error starting read: %d\n", error);
printf("-->Example Failed\n");
return error;
}
Expand All @@ -195,21 +184,16 @@ int main(void)
return error;
}

#ifdef DMA

while (DMA_FLAG) {}

#else

// Wait for read transaction to complete
while (READ_FLAG) {}

printf("-->Transaction complete\n\n");

if (READ_FLAG != E_NO_ERROR) {
printf("-->Error with UART_ReadAsync callback; %d\n", READ_FLAG);
printf("-->Error from UART read callback; %d\n", READ_FLAG);
fail++;
}

#endif

if ((error = memcmp(RxData, TxData, BUFF_SIZE)) != 0) {
printf("-->Error verifying Data: %d\n", error);
fail++;
Expand Down
34 changes: 11 additions & 23 deletions Examples/MAX78002/UART/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,9 @@

/***** Globals *****/
volatile int READ_FLAG;
volatile int DMA_FLAG;

/***** Functions *****/
#ifdef DMA
void DMA_Handler(void)
{
MXC_DMA_Handler();
DMA_FLAG = 0;
}
#else
#ifndef DMA
void UART1_Handler(void)
{
MXC_UART_AsyncHandler(MXC_UART1);
Expand Down Expand Up @@ -117,11 +110,7 @@ int main(void)

memset(RxData, 0x0, BUFF_SIZE);

#ifdef DMA
MXC_DMA_ReleaseChannel(0);
MXC_NVIC_SetVector(DMA0_IRQn, DMA_Handler);
NVIC_EnableIRQ(DMA0_IRQn);
#else
#ifndef DMA
NVIC_ClearPendingIRQ(UART1_IRQn);
NVIC_DisableIRQ(UART1_IRQn);
MXC_NVIC_SetVector(UART1_IRQn, UART1_Handler);
Expand All @@ -143,6 +132,12 @@ int main(void)

printf("-->UART Initialized\n\n");

#ifdef DMA
// Automatically set up DMA handlers/ISRs
MXC_UART_SetAutoDMAHandlers(READING_UART, true);
MXC_UART_SetAutoDMAHandlers(WRITING_UART, true);
#endif

mxc_uart_req_t read_req;
read_req.uart = MXC_UART1;
read_req.rxData = RxData;
Expand All @@ -160,8 +155,7 @@ int main(void)
write_req.callback = NULL;

READ_FLAG = 1;
DMA_FLAG = 1;

MXC_UART_ClearRXFIFO(MXC_UART1); // Clear any previously pending data
#ifdef DMA
error = MXC_UART_TransactionDMA(&read_req);
#else
Expand All @@ -182,20 +176,14 @@ int main(void)
return error;
}

#ifdef DMA

while (DMA_FLAG) {}

#else

while (READ_FLAG) {}

if (READ_FLAG != E_NO_ERROR) {
printf("-->Error with UART_ReadAsync callback; %d\n", READ_FLAG);
printf("-->Error from UART read callback; %d\n", READ_FLAG);
fail++;
}

#endif
printf("-->Transaction complete\n\n");

if ((error = memcmp(RxData, TxData, BUFF_SIZE)) != 0) {
printf("-->Error verifying Data: %d\n", error);
Expand Down
4 changes: 4 additions & 0 deletions Libraries/CMSIS/Device/Maxim/MAX32665/Include/max32665.h
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,10 @@ typedef enum {
((i) == 7) ? DMA15_IRQn : \
0))

#define MXC_DMA_CH_GET_IRQ(i) \
(((i) > (MXC_DMA_CH_OFFSET - 1)) ? MXC_DMA1_CH_GET_IRQ(i % MXC_DMA_CH_OFFSET) : \
MXC_DMA0_CH_GET_IRQ(i))

/* Create alias for MXC_DMA0 for backwards compatibility with code that was
written for parts that only had one DMA instance. */
#define MXC_DMA MXC_DMA0
Expand Down
Loading