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

cpu/stm32f1: reworked UART driver #4952

Merged
merged 5 commits into from
Mar 16, 2016

Conversation

haukepetersen
Copy link
Contributor

now using a simple trick silently introduced with #4840 to put the CPU to sleep at least a little bit during transmission of bytes...

@haukepetersen haukepetersen added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation 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 Community: Hack'n'ACK candidate This PR is a candidate for review and discussion during one of RIOT's monthly Hack'n'ACK parties labels Mar 3, 2016
@haukepetersen haukepetersen added this to the Release 2016.04 milestone Mar 3, 2016
@haukepetersen
Copy link
Contributor Author

rebased

@PeterKietzmann: ping

while (!(dev->SR & USART_SR_TXE)) {}
dev->DR = data[i];
while(!(dev(uart)->SR & USART_SR_TXE)) {
cpu_sleep_until_event();
Copy link
Member

Choose a reason for hiding this comment

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

Is an event generated when the byte is transmitted?

Copy link
Member

Choose a reason for hiding this comment

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

Can this be affected by #5085?

Copy link
Member

Choose a reason for hiding this comment

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

It should not be affected apart from working correctly :)

@lebrush Yes an event is generated because the TXE and UE interrupts are enabled. :)

Copy link
Member

Choose a reason for hiding this comment

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

Nice affect ;-)

@lebrush
Copy link
Member

lebrush commented Mar 16, 2016

The code looks good to me 👍

@@ -39,6 +39,9 @@ extern "C" {
#define CLOCK_AHB_DIV RCC_CFGR_HPRE_DIV1 /* AHB clock -> 72MHz */
#define CLOCK_APB2_DIV RCC_CFGR_PPRE2_DIV1 /* APB2 clock -> 72MHz */
#define CLOCK_APB1_DIV RCC_CFGR_PPRE1_DIV2 /* APB1 clock -> 36MHz */
/* resulting bus clocks */
#define CLOCK_APB1 (CLOCK_CORECLOCK / 2)
Copy link
Member

Choose a reason for hiding this comment

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

If I see it correctly, macros in l39-41 aren't used anywhere thus can be removedas well. Having a note for the division by two (like resulting clock frequencies som lines above) should fit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not correct -> have a look at the cpu/stm32f1/cpu.c...

@PeterKietzmann
Copy link
Member

Besides minor comments the PR looks fine. I just tested on an iotlalb node with UART_0. Don't have other (relevant) hardware available

@haukepetersen haukepetersen added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Mar 16, 2016
@haukepetersen
Copy link
Contributor Author

Rebased and took out the timer fixes (will open another PR for them). But when re-testing, the UART did not work anymore after #5085 was merged. So for now, I removed the call to cpu_sleep_until_event. We might want to re-add this once we figure out how to get it to work properly.

@DipSwitch
Copy link
Member

Maybe the pending status must be cleared of TXE and UE.

@lebrush
Copy link
Member

lebrush commented Mar 16, 2016

I still don't have a full overview of the difference between events and interrupts... but might it be because the TXEIE is not set?

@DipSwitch
Copy link
Member

@lebrush Yup that must be it =)

@haukepetersen
Copy link
Contributor Author

that would make sense. I thought that the TX interrupt event (without the TXIE bit actually set) would already count as an event, but this seems not to be true. So maybe this local sleep concept does not work as easily as I thought...

@PeterKietzmann
Copy link
Member

Looks fine for me. UART_0 still works on iotlab-m3, surprise... Would be nice if someone could check if fox or/and the nucleo board still work. Otherwise green lights from my side.

@jnohlgard
Copy link
Member

AFAIK what hardware events that set the SEV event flag is completely up to the CPU vendor to choose, so if it works in one way on nrf5x it won't necessarily be the same concept on stm32.

@DipSwitch
Copy link
Member

@haukepetersen The event interface is only available in the ARM interrupt controller and sleep manager. So for an event to be generated an interrupt line to the NVIC/interrupt controller must set it's pending state.

Edit: The interrupt source in the peripheral must be enabled but the interrupt doesn't have to be enabled in the NVIC. :)

@haukepetersen
Copy link
Contributor Author

@DipSwitch: that makes actually very much sense.

@PeterKietzmann: I have also no other board than the iotlab here. I think for the fox we have no possibility to test at the moment, same goes for the spark-core, as mine is broken. Not sure who has access to the nucleo... So my bet would be: verify for the iotlab and have a good look at the config for the other boards. And as Murdock is happy, I say that should be sufficient...

@DipSwitch
Copy link
Member

How about something like this?

DipSwitch@b64f2d5

@haukepetersen
Copy link
Contributor Author

@DipSwitch: I think it would work, but then it would make more sense to use DMA right away... I tend to leave it as is for this PR and then we can open a new one improving it.

@DipSwitch
Copy link
Member

DipSwitch commented Mar 16, 2016 via email

@haukepetersen
Copy link
Contributor Author

ALL CIs are happy -> and go.

haukepetersen added a commit that referenced this pull request Mar 16, 2016
cpu/stm32f1: reworked UART driver
@haukepetersen haukepetersen merged commit 7dc6610 into RIOT-OS:master Mar 16, 2016
@haukepetersen haukepetersen deleted the opt_f1_uart branch March 16, 2016 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Community: Hack'n'ACK candidate This PR is a candidate for review and discussion during one of RIOT's monthly Hack'n'ACK parties 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 Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants