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

New Platform: Msp432 #1911

Merged
merged 44 commits into from Jul 24, 2020
Merged

New Platform: Msp432 #1911

merged 44 commits into from Jul 24, 2020

Conversation

lebakassemmerl
Copy link
Contributor

@lebakassemmerl lebakassemmerl commented Jun 5, 2020

New Platform Support for the MSP-EXP432P401R Eval-Board

This pull-request adds support for MSP432P401R chip from Texas Instruments.
The implementation is currently very, very basic, only the GPIO-module is properly implemented in order to create a panic-handler which blinks an LED and to be able to test a simple user-space application.

If this PR will be accepted, the next step would be to implement the UART and timer modules for supporting debug-output and delays in userspace.

Adding a Platform to Tock Repository

  • The hardware must be widely available. Generally that means the hardware platform can be purchased online.
  • The port of Tock to the platform must include at least:
    • Console support so that debug!() and printf() work.
    • Timer support.
    • GPIO support with interrupt functionality.
  • The contributor must be willing to maintain the platform, at least initially, and help test the platform for future releases.

@lebakassemmerl lebakassemmerl changed the title Msp432 New Platform: Msp432 Jun 5, 2020
@alistair23
Copy link
Contributor

Thanks for the PR!!!

Would you mind rebasing on master? It looks like GitHub is confused and has included other patches in the PR. It makes it hard to review your changes.

Also the Tock porting guide gives some hints for porting: https://github.com/tock/tock/blob/master/doc/Porting.md#adding-a-platform-to-tock-repository
It also specifies that you need a working console (and timer but that might be less important) before the board is merged.

@alistair23
Copy link
Contributor

It also looks like the tests are failing. Make sure to run at least make ci-nosetup locally. For new boards the CI check can be helpful in finding bugs (it checks all of your register offsets).

@lebakassemmerl
Copy link
Contributor Author

Hi!
Yes, of course. I will rebase it on master. Also I will make sure that the test won't fail.

Concerning the console and timer: I read this guide and somewhere at the beginning it said that after GPIO is working it's a good time to open a pull request. So should I close/delete this PR, fix my tests, get the console working and open a new one?

@alistair23
Copy link
Contributor

Great! Thanks.

I think opening a PR makes sense. It lets everyone know what you are working on (so we don't duplicate efforts). It is also a great way to get feedback.

It might make sense to convert it to a draft PR until you have the tests and UART working though.

@bradjc
Copy link
Contributor

bradjc commented Jun 5, 2020

Very cool!

Can I ask what attracted you to this board/MCU?

@lebakassemmerl
Copy link
Contributor Author

Yeah, sure!

I'm doing my master thesis in porting Tock to a new platform, and my only 'requirement' was to choose a platform which is of course not supported yet and where a cheap evaluation board exists. In our university (FH Joanneum) we work a lot with all forms of TI products, so I had a look at their microcontroller boards. I chose this particular one because openOCD had good support for it, it contains a quite new Cortex-M4-based chip and the board costs only 20$.

@lebakassemmerl
Copy link
Contributor Author

Hi!

So far I managed it to get the UART in TX direction working in order to print panic- and debug-messages. Is it necessary for a first pull into the main-repo to get also the RX-functionality working?

Also the GPIO implementation doesn't support interrupts at the moment. Is this also necessary to get merged?

@alistair23
Copy link
Contributor

You don't need to have RX working, so that's fine. For GPIO I think that's also ok.

Copy link
Contributor

@alistair23 alistair23 left a comment

Choose a reason for hiding this comment

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

Looks REALLY good! :)

I have added some comments, they should all be pretty small. Overall this looks really good. I didn't compare it to the datasheet but everything looks reasonable.

Do you mind addressesing the comments and then I'll have another look?

.vscode/launch.json Outdated Show resolved Hide resolved
boards/msp_exp432p401r/Makefile Outdated Show resolved Hide resolved
boards/msp_exp432p401r/Makefile Outdated Show resolved Hide resolved
boards/msp_exp432p401r/README.md Outdated Show resolved Hide resolved
boards/msp_exp432p401r/src/io.rs Outdated Show resolved Hide resolved
chips/msp432/src/pcm.rs Outdated Show resolved Hide resolved
chips/msp432/src/pcm.rs Outdated Show resolved Hide resolved
chips/msp432/src/wdt.rs Outdated Show resolved Hide resolved
chips/msp432/src/wdt.rs Outdated Show resolved Hide resolved
chips/msp432/src/sysctl.rs Outdated Show resolved Hide resolved
@lebakassemmerl
Copy link
Contributor Author

Looks REALLY good! :)

I have added some comments, they should all be pretty small. Overall this looks really good. I didn't compare it to the datasheet but everything looks reasonable.

Do you mind addressesing the comments and then I'll have another look?

I think I have addressed all your comments with the latest commits.
So, when you find the time, please have another look (:

Copy link
Member

@ppannuto ppannuto left a comment

Choose a reason for hiding this comment

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

Overall, looks great!

boards/msp_exp432p401r/Makefile Show resolved Hide resolved
#![no_std]
#![cfg_attr(not(doc), no_main)]
#![feature(asm, core_intrinsics)]
// #![deny(missing_docs)]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// #![deny(missing_docs)]
#![deny(missing_docs)]

This still needs to be addressed. Should just be the listed change here.

boards/msp_exp432p401r/src/main.rs Outdated Show resolved Hide resolved
chips/msp432/src/cs.rs Outdated Show resolved Hide resolved
chips/msp432/src/cs.rs Outdated Show resolved Hide resolved
chips/msp432/src/flctl.rs Show resolved Hide resolved
chips/msp432/src/pcm.rs Show resolved Hide resolved
chips/msp432/src/lib.rs Outdated Show resolved Hide resolved
chips/msp432/src/uart.rs Outdated Show resolved Hide resolved
chips/msp432/src/uart.rs Show resolved Hide resolved
@alistair23
Copy link
Contributor

When you address a comment can you mark it as resolved?

@lebakassemmerl
Copy link
Contributor Author

When you address a comment can you mark it as resolved?

Sure! I didn't know that I was supposed to mark the comments as resolved.

Copy link
Member

@ppannuto ppannuto left a comment

Choose a reason for hiding this comment

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

Take a look at the SAM4L spi implementation for an example of PeripheralManager use. The idea is that the manager encapsulates the registers, so all register access must go through the manager. That way, hardware is provably always locked/unlocked at compile time.

e.g. when accessing registers, first create an instance of the manager: https://github.com/tock/tock/blob/master/chips/sam4l/src/spi.rs#L264
helper functions take a reference to the manager: https://github.com/tock/tock/blob/master/chips/sam4l/src/spi.rs#L241

chips/msp432/src/cs.rs Outdated Show resolved Hide resolved
chips/msp432/src/cs.rs Outdated Show resolved Hide resolved
ppannuto
ppannuto previously approved these changes Jul 13, 2020
Copy link
Member

@ppannuto ppannuto left a comment

Choose a reason for hiding this comment

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

I think this is looking pretty much ready! Very exciting!

@ppannuto
Copy link
Member

I think you can move this from a Draft PR to a full-fledged one at the point :)

@lebakassemmerl lebakassemmerl marked this pull request as ready for review July 13, 2020 17:00
@lebakassemmerl
Copy link
Contributor Author

I implemented no a very first version for handling GPIO interrupts. However, there is a problem with this controller, it does NOT support detecting interrupts at the falling edge and at the rising edge simultaneously. Just for testing the implementation with the button-capsule I detect only falling edges where actually both should be detected.

How should I solve this problem? Just 'ignore' the fact that both should be detected? Maybe panic!()? Or maybe any kind of software implementation (However I have no idea how this could be done within Tock)?

@hudson-ayers
Copy link
Contributor

I implemented no a very first version for handling GPIO interrupts. However, there is a problem with this controller, it does NOT support detecting interrupts at the falling edge and at the rising edge simultaneously. Just for testing the implementation with the button-capsule I detect only falling edges where actually both should be detected.

How should I solve this problem? Just 'ignore' the fact that both should be detected? Maybe panic!()? Or maybe any kind of software implementation (However I have no idea how this could be done within Tock)?

Regarding a software implementation, I think it would basically involve re-configuring a pin to check for the other edge type each time an interrupt arrived for that pin. This would just be done in the chip GPIO driver -- basically when a falling edge interrupt arrives, check that the pin is still low, and if so configure that pin to look for a rising edge interrupt, and vice-versa. Unfortunately it would have to take place in the bottom half interrupt handler, which means there is the possibility for large enough delays that interrupts could be missed, but I think this is still a better solution than only handling interrupts in one direction.

@lebakassemmerl
Copy link
Contributor Author

I implemented no a very first version for handling GPIO interrupts. However, there is a problem with this controller, it does NOT support detecting interrupts at the falling edge and at the rising edge simultaneously. Just for testing the implementation with the button-capsule I detect only falling edges where actually both should be detected.
How should I solve this problem? Just 'ignore' the fact that both should be detected? Maybe panic!()? Or maybe any kind of software implementation (However I have no idea how this could be done within Tock)?

Regarding a software implementation, I think it would basically involve re-configuring a pin to check for the other edge type each time an interrupt arrived for that pin. This would just be done in the chip GPIO driver -- basically when a falling edge interrupt arrives, check that the pin is still low, and if so configure that pin to look for a rising edge interrupt, and vice-versa. Unfortunately it would have to take place in the bottom half interrupt handler, which means there is the possibility for large enough delays that interrupts could be missed, but I think this is still a better solution than only handling interrupts in one direction.

Ok, thanks!
Then I will try to implement a first software based approach for detecting both edges simultaneously.

@lebakassemmerl
Copy link
Contributor Author

I have now implemented a first approach for detecting both interrupts by software. Can somebody please have a look on it if the implementation makes sense?
I tested it within the debugger, the basic functionality seems to work, after a rising edge it detects a falling one and vice versa. However I am not sure if I didn't make any subtle mistakes in this implementation.

@lebakassemmerl
Copy link
Contributor Author

lebakassemmerl commented Jul 23, 2020

With the latest commit I added some missing lifetime specifiers in the GPIO module. However, since the struct PinJ basically doesn't need any lifetime (because it doesn't support interrupts), the macro I created doesn't work any more. For this reason I added a PhantomData<&'a ()> member to PinJ which makes it behave as it would have a lifetime. Is this the intended way to go or is there a better one?

@ppannuto ppannuto added the last-call Final review period for a pull request. label Jul 24, 2020
@bradjc
Copy link
Contributor

bradjc commented Jul 24, 2020

bors r+

@bors bors bot merged commit 8bb0709 into tock:master Jul 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
last-call Final review period for a pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants