Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix for https://github.com/arduino/ArduinoCore-renesas/issues/12 #31

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

Closed
maidnl wants to merge 1 commit into main from SPI_mode_and_bit_order_not_set_correctly_fix

Conversation

Copy link
Contributor

@maidnl maidnl commented Jul 4, 2023

fix for #12

Copy link

CLAassistant commented Jul 4, 2023
edited
Loading

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@aentinger aentinger left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Please cleanup the comments and possible consider replacing ONE_BIT, TWO_BITS with relevant constants from the FSP layer.

@@ -403,16 +426,24 @@ void ArduinoSPI::configSpiSci(arduino::SPISettings const & settings)
uint32_t smr = R_SCI0_SMR_CM_Msk;

/* Configure CPHA setting. */
spmr |= (uint32_t) clk_phase << 7;
uint32_t mask = (ONE_BIT << SCI_CKPH_POS);
spmr &= ~(uint32_t)mask; // reset bit 0
Copy link
Contributor

@aentinger aentinger Jul 5, 2023

Choose a reason for hiding this comment

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

Is this comment // reset bit 0 true? It looks to me like its copy and paste from the baud rate generator clock divider configuration.


/* Configure CPOL setting. */
spmr |= (uint32_t) clk_polarity << 6;
mask = (ONE_BIT << SCI_CKPOL_POS);
Copy link
Contributor

@aentinger aentinger Jul 5, 2023

Choose a reason for hiding this comment

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

I'm not really happy with the generic ONE_BIT, TWO__BITS defines. Maybe consider using the FSP layer provided constants, i.e.

-mask = (ONE_BIT << SCI_CKPOL_POS);
+mask = (SPI_CLK_POLARITY_HIGH << SCI_CKPOL_POS);

? This one's a matter of taste though.

Copy link
Member

facchinm commented Jul 7, 2023

Superseded by #13

Copy link
Contributor

I think this should be reopened since it fixes additional problems I didn't catch in my PR: clearing the mode and bit order bits so you can revert back if talking to multiple devices, and applies the same fixes to configSpiSci.

@@ -374,23 +385,35 @@ void ArduinoSPI::configSpi(arduino::SPISettings const & settings)
uint32_t spcmd0 = _spi_ctrl.p_regs->SPCMD[0];
Copy link
Contributor

@trevor-makes trevor-makes Jul 8, 2023

Choose a reason for hiding this comment

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

I wonder if it would be clearer to just modify the register in-place to make use of Renesas' struct definitions, so all of the masking and bit shifting would be handled implicitly. Like so:

auto& spcmd0 = _spi_ctrl.p_regs->SPCMD_b[0]; // note SPCMD_b not SPCMD
spcmd0.CPHA = clk_phase;
spcmd0.CPOL = clk_polarity;
spcmd0.LSBF = bit_order;
spcmd0.BRDV = spck_div.brdv;

Copy link
Contributor

@trevor-makes trevor-makes Jul 8, 2023

Choose a reason for hiding this comment

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

See definition here

@@ -403,16 +426,24 @@ void ArduinoSPI::configSpiSci(arduino::SPISettings const & settings)
uint32_t smr = R_SCI0_SMR_CM_Msk;
Copy link
Contributor

@trevor-makes trevor-makes Jul 8, 2023

Choose a reason for hiding this comment

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

Likewise, maybe this could be:

auto& spmr = _spi_sci_ctrl.p_reg->SPMR_b;
spmr.CKPH = clk_phase;
spmr.CKPOL = clk_polarity;
auto& scmr = _spi_sci_ctrl.p_reg->SCMR_b;
scmr.SDIR = bit_order;
auto& smr = _spi_sci_ctrl.p_reg->SMR_b;
smr.CKS = clk_div.cks;

Copy link
Contributor

Superseded by #45 .

pennam pushed a commit to pennam/ArduinoCore-renesas that referenced this pull request Aug 9, 2023
@per1234 per1234 deleted the SPI_mode_and_bit_order_not_set_correctly_fix branch August 12, 2023 14:47
cristidragomir97 pushed a commit to cristidragomir97/ArduinoCore-renesas that referenced this pull request May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
2 more reviewers

@trevor-makes trevor-makes trevor-makes left review comments

@aentinger aentinger aentinger requested changes

Reviewers whose approvals may not affect merge requirements
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /