Skip to content

Conversation

@jnohlgard
Copy link
Member

Contribution description

The Kinetis LPUART hardware module can choose from multiple clock sources, to use the module the user needs to select a clock source by setting a bitfield in the SIM_SOPT2 register. This PR moves this configuration into the periph uart driver, to reduce the code duplication in board_init between different boards and to make it easier to switch UART settings on an existing board.
The only existing board which has a LPUART module is the FRDM-K22F, but the module is not used in the default configuration, so this PR is mainly in preparation for the FRDM-KW41Z in #6995 which only has LPUART type UART hardware modules.

Issues/PRs references

Split from #6995
Required by #6995 for functional UART.

@jnohlgard jnohlgard added Platform: ARM Platform: This PR/issue effects ARM-based platforms Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation Area: drivers Area: Device drivers CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Mar 2, 2018
@jnohlgard jnohlgard added this to the Release 2018.04 milestone Mar 2, 2018
@jnohlgard jnohlgard requested a review from kYc0o March 2, 2018 07:15
Copy link
Contributor

@kYc0o kYc0o left a comment

Choose a reason for hiding this comment

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

I have some small doubts but looks ok in general.

#define SIM_SOPT2_LPUART0SRC_MASK SIM_SOPT2_LPUARTSRC_MASK
#define SIM_SOPT2_LPUART0SRC_SHIFT SIM_SOPT2_LPUARTSRC_SHIFT
#define SIM_SOPT2_LPUART0SRC SIM_SOPT2_LPUARTSRC
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

Can these defines be aligned? Just to see that they're actually defining a value.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will fix


/* Remember to select a module clock in board_init! (SIM->SOPT2[LPUART0SRC]) */
/* Set LPUART clock source */
#ifdef SIM_SOPT2_LPUART0SRC
Copy link
Contributor

Choose a reason for hiding this comment

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

The value of this definition doesn't matter? It only needs to be defined to execute the code below? It's just because above there is:

#define SIM_SOPT2_LPUART0SRC SIM_SOPT2_LPUARTSRC

thus the value might be needed or evaluated.

Copy link
Member Author

@jnohlgard jnohlgard Mar 2, 2018

Choose a reason for hiding this comment

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

They are defined by the vendor headers for the CPUs which have the appropriate hardware module. The definition in cpu_conf_kinetis.h is only a compatibility definition for some CPU headers which have named the bit field LPUARTSRC instead of LPUART0SRC. See the other definitions in the same area in cpu_conf_kinetis.h.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok I got it. Thanks!


#ifndef LPUART_0_SRC
/* Default LPUART clock setting to avoid compilation failures, define this in
* periph_conf.h to set board specific configuration if using the LPUART. */
Copy link
Contributor

@kYc0o kYc0o Mar 2, 2018

Choose a reason for hiding this comment

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

Maybe this comment can be above the #ifndef?

Copy link
Member Author

Choose a reason for hiding this comment

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

addressed

SIM_SOPT2_LPUART0SRC(LPUART_0_SRC);
}
#endif
#ifdef SIM_SOPT2_LPUART1SRC
Copy link
Contributor

Choose a reason for hiding this comment

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

Though I see a define for SIM_SOPT2_LPUART0SRC, I can't find for SIM_SOPT2_LPUART1SRC. Is this intentional? Same for SIM_SOPT2_LPUART1SRC_MASK used below, since there is a definition for SIM_SOPT2_LPUART0SRC_MASK.

Copy link
Member Author

Choose a reason for hiding this comment

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

LPUART1SRC only exist for CPUs which have two or more lpuart modules (LPUART0, LPUART1). Therefore we need the preprocessor conditional to avoid compilation errors on the CPUs which don't have these modules.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok I see, that's right for me.

@jnohlgard
Copy link
Member Author

@kYc0o aligned definitions in cpu_conf_kinetis.h

@jnohlgard jnohlgard force-pushed the pr/kinetis-lpuart-clocking branch from 65b4ac7 to fea2d71 Compare March 2, 2018 12:46
@kYc0o
Copy link
Contributor

kYc0o commented Mar 2, 2018

Perfect, I think everything is in order here, so you may squash and merge once everything is green.

@jnohlgard jnohlgard force-pushed the pr/kinetis-lpuart-clocking branch from fea2d71 to 2bdf0bf Compare March 2, 2018 13:39
@jnohlgard
Copy link
Member Author

@kYc0o squashed, missing ACK

Copy link
Contributor

@kYc0o kYc0o left a comment

Choose a reason for hiding this comment

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

ACK.

@jnohlgard jnohlgard merged commit a7f06f8 into RIOT-OS:master Mar 2, 2018
@jnohlgard jnohlgard deleted the pr/kinetis-lpuart-clocking branch March 2, 2018 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: drivers Area: Device drivers CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: ARM Platform: This PR/issue effects ARM-based platforms Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants