Skip to content

boards: support for Olimex MSP430-H1611 board #19558

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

Merged
merged 2 commits into from
May 16, 2023

Conversation

maribu
Copy link
Member

@maribu maribu commented May 7, 2023

Contribution description

  • implement a clock driver so that boards declare their clock configuration, rather than initializing the CPU clock in board_init() by hand
    • Note: A board can still overwrite the weak symbol clock_init() in case some really crazy things should happen
  • add support for the Olimex-H1611 board

Testing procedure

make -C examples/default BOARD=olimex-h1611 BUILD_IN_DOCKER=1 flash term
[...]
2023-05-07 20:51:54,151 # main(): This is RIOT! (Version: 2023.07-devel-243-ga49f166-boards/olimex-msp430-h1611)
2023-05-07 20:51:54,171 # Welcome to RIOT!
> help
2023-05-07 20:51:57,144 # help
2023-05-07 20:51:57,182 # Command              Description
2023-05-07 20:51:57,228 # ---------------------------------------
2023-05-07 20:51:57,292 # pm                   interact with layered PM subsystem
2023-05-07 20:51:57,364 # ps                   Prints information about running threads.
2023-05-07 20:51:57,407 # reboot               Reboot the node
2023-05-07 20:51:57,485 # saul                 interact with sensors and actuators using SAUL
2023-05-07 20:51:57,541 # version              Prints current RIOT_VERSION
> reboot
2023-05-07 20:52:00,272 # reboot�main(): This is RIOT! (Version: 2023.07-devel-243-ga49f166-boards/olimex-msp430-h1611)
2023-05-07 20:52:00,292 # Welcome to RIOT!
> saul
2023-05-07 20:52:04,185 # saul
2023-05-07 20:52:04,204 # No devices found
> version
2023-05-07 20:52:05,949 # version
2023-05-07 20:52:06,011 # 2023.07-devel-243-ga49f166-boards/olimex-msp430-h1611

Issues/PRs references

None

@maribu maribu added Type: new feature The issue requests / The PR implemements a new feature for RIOT CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels May 7, 2023
@github-actions github-actions bot added Area: boards Area: Board ports Area: cpu Area: CPU/MCU ports Area: doc Area: Documentation Area: Kconfig Area: Kconfig integration Area: tools Area: Supplementary tools Platform: MSP Platform: This PR/issue effects MSP-based platforms labels May 7, 2023
@riot-ci
Copy link

riot-ci commented May 7, 2023

Murdock results

✔️ PASSED

e7d1c4a boards/olimex-msp430-h1611: new board

Success Failures Total Runtime
6931 0 6931 10m:07s

Artifacts

Comment on lines +39 to +40
.main_clock_source = MAIN_CLOCK_SOURCE_DCOCLK,
.submain_clock_source = SUBMAIN_CLOCK_SOURCE_DCOCLK,
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: The MSP430_HAS_EXTERNAL_CRYSTAL would indicate that the XT2 clock should be used instead of the DCO. However, the msp430_init_dco() in the TelosB's board.c configures and calibrates the DCO as clock source regardless of that macro. It seems to be a copy-paste error.

Also note: It should now be possible to run the DCO at 4 MHz instead of ~2.5 MHz, as the DCO calibration is a bit more robust.

@maribu maribu force-pushed the boards/olimex-msp430-h1611 branch from 287d27e to 8f53b23 Compare May 7, 2023 19:05
@maribu
Copy link
Member Author

maribu commented May 7, 2023

Note: I also tested the clock initialization on the Olimex MSP430-H1611 with an 8 MHz crystal inserted into the Q2 socket and the clock_params adjusted to use XT2 at 8 MHz as main and submain clock and it worked fine.

* @name Clock configuration
* @{
*/
/** @todo Move all clock configuration code here from the board.h */
#define CLOCK_CORECLOCK (7372800U)
Copy link
Member Author

@maribu maribu May 7, 2023

Choose a reason for hiding this comment

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

How did this ever work? The clock was initialized to run at ~2.5 MHz from DCO due to

#define MSP430_INITIAL_CPU_SPEED    2457600uL
#define F_CPU                       MSP430_INITIAL_CPU_SPEED
#define F_RC_OSCILLATOR             32768
#define MSP430_HAS_DCOR             1
#define MSP430_HAS_EXTERNAL_CRYSTAL 0

But CLOCK_CORECLOCK was ~7.4 MHz ans so was CLOCK_CMCLK, which was used to configure the UART symbol rate to 9600 Baud. The actual symbol rate like was then 3200 Baud due to this mismatch :-/


Update: I double checked: The datasheet says that the DCO tops out at 5.4 MHz maximum, even if the the silicon lottery gave one an extra fast DCO (the production variance is said to be significant) and the supply voltage is extra high. In fact, 4.9 MHz is the typical max frequency at 3 V. The sanity test prevents more than 4 MHz to account for poor luck in the silicon lottery + a low supply voltage.

Copy link
Member Author

Choose a reason for hiding this comment

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

The good thing is that the compile time configuration sanity tests do indeed work and caught the issue.

@maribu maribu force-pushed the boards/olimex-msp430-h1611 branch from 8f53b23 to bb54f7a Compare May 7, 2023 19:17
@maribu maribu added the State: waiting for author State: Action by the author of the PR is required label May 8, 2023
@maribu
Copy link
Member Author

maribu commented May 8, 2023

I would like to change the DCO calibration algorithm. It is now basically the same approach as before with linear search, just some corner case handling added. This already reduced boot up time from about 4 secs with a 4 MHz DCO to about half a second (perceived duration, I didn't measure) but stopping the calibration once the settings are oscillating between "just a bit too slow" and "just a bit too fast". Still, boot up time is much faster when an external crystal is used. To some part this may be due to the CPU then running at 8 MHz instead of 4 MHz, but I also believe that the DCO calibration is taking ages.

I would like to check if using a binary search for the correct DCO settings instead of the linear search yields a significant speed up. As a bonus, this will terminate naturally without having to detect that one is oscillating between "just a bit too fast" and "just a bit too slow" without hitting "just right" until seconds of brute force have passed.

(Some simple calculus indicates that indeed linear search among the hole configuration space takes 0.4375 seconds. So I think it is indeed sensible to give the binary search a try.)

@maribu maribu removed the State: waiting for author State: Action by the author of the PR is required label May 9, 2023
@maribu
Copy link
Member Author

maribu commented May 9, 2023

IMO the code with the binary search for the correct DCO calibration is indeed cleaner. I perceive the boot up time to be a bit faster now as well; I haven't done actual measurements though.

With the greatly reduced number of steps it is now also feasible to let the timer capture twice with the same DCO settings in place. That should result in higher precision, as now the full duration between two captures the DCO was clocking at the higher frequency (and it also become some time to settle). Again, no actual measurements done, but it at least is plausible that this is better.

Copy link
Contributor

@benpicco benpicco left a comment

Choose a reason for hiding this comment

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

Looks much nicer indeed.

I don't have the hardware, but maybe @kaspar030 or @miri64 still have an msb-430 and can verify this also still works on those boards.

extern "C" {
#endif

#define INFOMEM (0x1000)
Copy link
Contributor

Choose a reason for hiding this comment

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

any info on what this is?

Copy link
Member Author

@maribu maribu May 11, 2023

Choose a reason for hiding this comment

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

It is the start address of the info mem segment of the flash:

InfoMem

The info mem is actually just normally flash, but the blocks are smaller. This makes it more suitable as EEPROM replacement, as a read-modify-erase-write cycle would be faster due to the smaller block size.

It may be useful for an application to have that address to easily read application data from flash stored there. Likely, it would be better to use the linker (the vendor provided linker files define the INFOMEM memory) to access that, though.

Copy link
Contributor

Choose a reason for hiding this comment

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

If that's a hardware property (e.g. can't be configured by the board) it should be defined by the CPU - and be documented.

I reckon we also don't place firmware there, but instead have a special linker section for this memory?

Copy link
Member Author

Choose a reason for hiding this comment

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

That would be how IMO we should do it. As of now, it is up to the application developer to use it.

This is certainly on the list of todos for cleaning up the MSP430 platform; as well as cleaning up all of the periph drivers. (Likely the periph drivers are more pressing.)

My original plan was to get in support for the Olimex board without doing any cleanup, so that I can work and test the cleanup with real hardware without having to juggle to much out of tree code. However, adding another copy of the void msp430_init_dco(void) function implementing the exact same thing for every board is something that just felt too wrong.

Still, I would like to keep the INFOMEM as a define and on board level for now. Moving that to CPU level would however be swift and easy follow-up PR that I could do prior to cleaning up the peripherals.

Copy link
Contributor

@benpicco benpicco left a comment

Choose a reason for hiding this comment

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

Looks much nicer indeed.

I don't have the hardware, but maybe @kaspar030 or @miri64 still have an msb-430 and can verify this also still works on those boards.

@maribu maribu force-pushed the boards/olimex-msp430-h1611 branch 2 times, most recently from 95e2696 to 24f0691 Compare May 12, 2023 13:34
@github-actions github-actions bot added the Area: sys Area: System label May 12, 2023
@maribu maribu force-pushed the boards/olimex-msp430-h1611 branch 2 times, most recently from 1e92692 to 0cd6db1 Compare May 15, 2023 12:05
@bors
Copy link
Contributor

bors bot commented May 16, 2023

Build failed:

@maribu
Copy link
Member Author

maribu commented May 16, 2023

Yep, I should have listened to @aabadie 😅

I don't quite get why the insufficient_memory_tool didn't catch that, though. Maybe my container is out of date.

@maribu maribu added CI: full build disable CI build filter CI: no fast fail don't abort PR build after first error labels May 16, 2023
@maribu maribu force-pushed the boards/olimex-msp430-h1611 branch from e4f5e84 to 68c5396 Compare May 16, 2023 11:56
@github-actions github-actions bot added the Area: CI Area: Continuous Integration of RIOT components label May 16, 2023
@maribu
Copy link
Member Author

maribu commented May 16, 2023

Or maybe a rebase messed that up...

@maribu maribu force-pushed the boards/olimex-msp430-h1611 branch from 68c5396 to 48b3aa1 Compare May 16, 2023 12:42
@maribu maribu added CI: skip compile test If set, CI server will run only non-compile jobs, but no compile jobs or their dependent jobs and removed CI: full build disable CI build filter CI: no fast fail don't abort PR build after first error CI: skip compile test If set, CI server will run only non-compile jobs, but no compile jobs or their dependent jobs labels May 16, 2023
@maribu maribu force-pushed the boards/olimex-msp430-h1611 branch from 48b3aa1 to ee3a8ec Compare May 16, 2023 12:52
@maribu maribu force-pushed the boards/olimex-msp430-h1611 branch from ee3a8ec to e7d1c4a Compare May 16, 2023 13:03
@github-actions github-actions bot removed the Area: CI Area: Continuous Integration of RIOT components label May 16, 2023
@maribu
Copy link
Member Author

maribu commented May 16, 2023

bors retry

@bors
Copy link
Contributor

bors bot commented May 16, 2023

Build succeeded!

The publicly hosted instance of bors-ng is deprecated and will go away soon.

If you want to self-host your own instance, instructions are here.
For more help, visit the forum.

If you want to switch to GitHub's built-in merge queue, visit their help page.

@bors bors bot merged commit 070025f into RIOT-OS:master May 16, 2023
@maribu maribu deleted the boards/olimex-msp430-h1611 branch May 16, 2023 16:04
@maribu
Copy link
Member Author

maribu commented May 16, 2023

🎉 Thx for the review / testing.

maribu added a commit to maribu/RIOT that referenced this pull request Jun 3, 2023
df5c319 from
RIOT-OS#19558 broke the clock
configuration of the Z1 by relying on the incorrect documentation of
what clock is actually used. Closely reading the convoluted clock
initialization code revealed that no XT2 crystal is present (as also
indicated by some comments in `board.c`), contradicting the
`#define MSP430_HAS_EXTERNAL_CRYSTAL 1` in the `board.h`.

This now should restore behavior (but with calibrated DCO than
hard coded magic numbers).
maribu added a commit to maribu/RIOT that referenced this pull request Jun 7, 2023
df5c319 from
RIOT-OS#19558 broke the clock
configuration of the Z1 by relying on the incorrect documentation of
what clock is actually used. Closely reading the convoluted clock
initialization code revealed that no XT2 crystal is present (as also
indicated by some comments in `board.c`), contradicting the
`#define MSP430_HAS_EXTERNAL_CRYSTAL 1` in the `board.h`.

This now should restore behavior (but with calibrated DCO than
hard coded magic numbers).
bors bot added a commit that referenced this pull request Jun 7, 2023
19705: boards/z1: fix broken clock configuration r=maribu a=maribu

### Contribution description

The MSP430F2xx family has on RSEL bit more than the MSP430x1xxx family. The first commit updates the clock calibration accordingly.

df5c319 from #19558 broke the clock configuration of the Z1 by relying on the incorrect documentation of what clock is actually used. Closely reading the convoluted clock initialization code revealed that no XT2 crystal is present (as also indicated by some comments in `board.c`), contradicting the `#define MSP430_HAS_EXTERNAL_CRYSTAL 1` in the `board.h`.

The second commit should restore behavior (but with calibrated DCO than hard coded magic numbers).


19713: nanocoap: clean up coap_iterate_option(), make it public r=maribu a=benpicco



Co-authored-by: Marian Buschsieweke <marian.buschsieweke@posteo.net>
Co-authored-by: Benjamin Valentin <benjamin.valentin@ml-pa.com>
bors bot added a commit that referenced this pull request Jun 7, 2023
19705: boards/z1: fix broken clock configuration r=maribu a=maribu

### Contribution description

The MSP430F2xx family has on RSEL bit more than the MSP430x1xxx family. The first commit updates the clock calibration accordingly.

df5c319 from #19558 broke the clock configuration of the Z1 by relying on the incorrect documentation of what clock is actually used. Closely reading the convoluted clock initialization code revealed that no XT2 crystal is present (as also indicated by some comments in `board.c`), contradicting the `#define MSP430_HAS_EXTERNAL_CRYSTAL 1` in the `board.h`.

The second commit should restore behavior (but with calibrated DCO than hard coded magic numbers).


Co-authored-by: Marian Buschsieweke <marian.buschsieweke@posteo.net>
@benpicco benpicco added this to the Release 2023.07 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: boards Area: Board ports Area: cpu Area: CPU/MCU ports Area: doc Area: Documentation Area: examples Area: Example Applications Area: Kconfig Area: Kconfig integration Area: tests Area: tests and testing framework Area: tools Area: Supplementary tools CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: MSP Platform: This PR/issue effects MSP-based platforms Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants