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

feat(Examples): Add generic I2C RX/TX DMA vector flexibility to I2C examples for all parts #693

Merged
merged 32 commits into from
Sep 19, 2023

Conversation

sihyung-maxim
Copy link
Contributor

@sihyung-maxim sihyung-maxim commented Jul 28, 2023

Description

  • Add I2C DMA to I2C examples for all parts.
  • Add MXC_I2C_DMA_Init(...) to initialize the DMA and acquire DMA channels before calling MXC_I2C_MasterTransactionDMA(...). This allows you to set up generic DMA channel vectors during run-time rather than defining specific DMA channel interrupt handlers beforehand (not always going to acquire DMA channels 0 and 1).
  • Add MXC_I2C_DMA_GetRXChannel(...) and MXC_I2C_DMA_GetTXChannel(...) to grab the acquired RX/TX channels for a specific I2C instance (if DMA is used).
  • Update all I2C examples to be consistent with each other.
  • These changes are also backward-compatible with the previous way I2C DMA was set up. If the user doesn't call MXC_I2C_DMA_Init(...) to initialize the I2C DMA beforehand, then the `MXC_I2C_MasterTransactionDMA(...) function will initialize the DMA like how it was previously done. This is just an added option to set up generic DMA channel vectors since channels 0 and 1 won't always be acquired. These changes won't affect anyone's current projects if they choose to not use this option.

Checklist Before Requesting Review

  • PR Title follows correct guidelines.
  • Description of changes and all other relevant information.
  • (Optional) Link any related GitHub issues using a keyword
  • (Optional) Provide info on any relevant functional testing/validation. For API changes or significant features, this is not optional.

@github-actions github-actions bot added MAX32670 Related to the MAX32670 (ME15) MAX32675 Related to the MAX32675 (ME16) labels Jul 28, 2023
@aniebo20
Copy link

@sihyung-maxim Would the DMA i2c writes only occur once (regardless of the number of calls) because the states[i2cNum].writeDone flag is never reset in MXC_I2C_RevA_MasterTransactionDMA (i2c_reva.c)?

@sihyung-maxim
Copy link
Contributor Author

@sihyung-maxim Would the DMA i2c writes only occur once (regardless of the number of calls) because the states[i2cNum].writeDone flag is never reset in MXC_I2C_RevA_MasterTransactionDMA (i2c_reva.c)?

Yes, you're correct. It should be cleared before the transaction starts.

@sihyung-maxim
Copy link
Contributor Author

/clang-format-run

@github-actions github-actions bot added MAX32520 Related to the MAX32520 (ES17) MAX32570 Related to the MAX32570 (ME13) MAX32650 Related to the MAX32650 (ME10) MAX32655 Related to the MAX32655 (ME17) MAX32660 Related to the MAX32660 (ME11) MAX32665 Related to the MAX32665 (ME14) MAX32672 Related to the MAX32672 (ME21) MAX32680 Related to the MAX32680 (ME20) MAX32690 Related to the MAX32690 (ME18) MAX78000 Related to the MAX78000 (AI85) MAX78002 Related to the MAX78002 (AI87) MAX32662 Related to the MAX32662 (ME12) labels Jul 31, 2023
@sihyung-maxim sihyung-maxim changed the title feat(Examples): Add I2C DMA to I2C examples for MAX32670 and MAX32675 feat(Examples): Add generic I2C RX/TX DMA vector flexibility to I2C examples for all parts Jul 31, 2023

i2cNum = MXC_I2C_GET_IDX((mxc_i2c_regs_t *)i2c);

i2c->ctrl = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does setting the Reset bit in the GCR regs not clear all the I2C registers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, unfortunately, not all registers are cleared when you set the reset bit in the GCR.

int8_t i2cNum;
int8_t rxChannel;
int8_t txChannel;
mxc_dma_config_t rxConfig;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth considering adding either a parameter or another function to handle TX and RX separately. It seems like there are a fair number of applications which would either want to use DMA for TX or RX, but not necessarily both. If that is the case then it would be kind of silly to take two DMA channels when the user only needs one.

states[i2cNum].channelTx = txChannel;
states[i2cNum].channelRx = rxChannel;

states[i2cNum].dma_initialized = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider just using the channelTx/Rx to determine if the DMA has been initialized. Like, "if(channelTx == E_NO_DEVICE)..." If you choose to handle TX and RX separately that would eliminate the need for a second boolean as well.

@sihyung-maxim sihyung-maxim added WIP work in progress Needs Testing labels Aug 8, 2023
@sihyung-maxim
Copy link
Contributor Author

/clang-format-run

txChannel = MXC_DMA_AcquireChannel();
#endif

txConfig.ch = txChannel;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like txConfig and rxConfig are set but never used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're used when setting the appropriate register settings, but I removed them.

config.dstinc_en = 1;

srcdst.ch = channel;
srcdst.ch = states[i2cNum].channelRx;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check channelRx/Tx is configured before using?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change is in there. GitHub bugged out and didn't show the changes from the latest commit.

// Serve as a 16 byte loopback, returning data*2
for (int i = 0; i < I2C_BYTES; i++) {
Stxdata[i] = i;
Stxdata[i] = Srxdata[i];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant since Stxdata is already initialized in main. Ditto for other I2C examples.

- Merge remote-tracking branch 'remotes/upstream/main' into feat/me15_i2c_dma
@sihyung-maxim sihyung-maxim merged commit b4f31bd into main Sep 19, 2023
@sihyung-maxim sihyung-maxim deleted the feat/me15_i2c_dma branch September 19, 2023 15:25
EricB-ADI pushed a commit that referenced this pull request Nov 21, 2023
…xamples for all parts (#693)

Co-authored-by: sihyung-maxim <[email protected]>
Co-authored-by: Jake Carter <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MAX32520 Related to the MAX32520 (ES17) MAX32570 Related to the MAX32570 (ME13) MAX32650 Related to the MAX32650 (ME10) MAX32655 Related to the MAX32655 (ME17) MAX32660 Related to the MAX32660 (ME11) MAX32662 Related to the MAX32662 (ME12) MAX32665 Related to the MAX32665 (ME14) MAX32670 Related to the MAX32670 (ME15) MAX32672 Related to the MAX32672 (ME21) MAX32675 Related to the MAX32675 (ME16) MAX32680 Related to the MAX32680 (ME20) MAX32690 Related to the MAX32690 (ME18) MAX78000 Related to the MAX78000 (AI85) MAX78002 Related to the MAX78002 (AI87) Needs Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants