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/msp430: reorganize code #19733

Merged
merged 2 commits into from
Jul 4, 2023
Merged

cpu/msp430: reorganize code #19733

merged 2 commits into from
Jul 4, 2023

Conversation

maribu
Copy link
Member

@maribu maribu commented Jun 13, 2023

Contribution description

RIOT supports two distinct families of the MSP430: The MSP430 x1xx MCU family and the MSP430 F2xx/G2xx MCU family. For both incompatible MCU families the code was located in the msp430fxyz folder, resulting in case of the UART driver in particularly bizarre code looking roughly like this:

#ifndef UART_USE_USCI
/* implementation of x1xx peripheral ... */
#else
/* implementation of F2xx/G2xx peripheral ... */
#endif
/* zero shared code between both variants */

This moves peripheral drivers shared between the two families to msp430_common and splits the SPI and UART driver into two MCU families.

In addition, it cleans up the msp430_regs.h by dropping most of it and using the macros and symbols provided by the vendor header files. There is little reason for us to maintain constants when TI is already doing that.

Testing procedure

This only moves code, it doesn't change it. Other than debug symbols changed, I don't expect differences in the generated binaries.

Issues/PRs references

None

@maribu maribu added State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Jun 13, 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 Platform: MSP Platform: This PR/issue effects MSP-based platforms labels Jun 13, 2023
@riot-ci
Copy link

riot-ci commented Jun 13, 2023

Murdock results

✔️ PASSED

45b353c cpu/msp430: make use of vendor header files

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

Artifacts

@github-actions github-actions bot added the Area: tests Area: tests and testing framework label Jun 13, 2023
@github-actions github-actions bot added Area: build system Area: Build system Area: tools Area: Supplementary tools labels Jun 14, 2023
@maribu maribu force-pushed the msp430-cleanup branch 4 times, most recently from fa71e09 to 6e743fd Compare June 14, 2023 20:14
@maribu
Copy link
Member Author

maribu commented Jun 15, 2023

Testing results:

examples/default on olimex-msp430-h1611:

$ ~/Repos/software/RIOT/msp430-cleanup/examples/default % make BOARD=olimex-msp430-h1611 flash term      
Building application "default" for "olimex-msp430-h1611" with MCU "msp430_x1xx".

[...]
   text	  data	   bss	   dec	   hex	filename
  15338	   190	  1132	 16660	  4114	/home/maribu/Repos/software/RIOT/msp430-cleanup/examples/default/bin/olimex-msp430-h1611/default.elf
mspdebug -j olimex "prog /home/maribu/Repos/software/RIOT/msp430-cleanup/examples/default/bin/olimex-msp430-h1611/default.hex"
MSPDebug version 0.25 - debugging tool for MSP430 MCUs
Copyright (C) 2009-2017 Daniel Beer <dlbeer@gmail.com>
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Chip info database from MSP430.dll v3.3.1.4 Copyright (C) 2013 TI, Inc.

Resetting Olimex command processor...
Initializing FET...
FET protocol version is 20000007
Set Vcc: 3000 mV
Configured for JTAG (2)
Sending reset...
Using Olimex identification procedure
Device ID: 0xf16c
  Code start address: 0x4000
  Code size         : 49152 byte = 48 kb
  RAM  start address: 0x200
  RAM  end   address: 0x9ff
  RAM  size         : 2048 byte = 2 kb
Device: MSP430F1611
Number of breakpoints: 8
fet: FET returned error code 34 (Not supported by selected interface or interface is not initialized)
fet: warning: message C_IDENT3 failed
fet: FET returned NAK
warning: device does not support power profiling
Chip ID data:
  ver_id:         6cf1
  ver_sub_id:     0000
  revision:       20
  fab:            40
  self:           0000
  config:         00
  fuses:          00
Device: MSP430F1611
Erasing...
Programming...
Writing 4096 bytes at 4000...
Writing 4096 bytes at 5000...
Writing 4096 bytes at 6000...
Writing 3236 bytes at 7000...
Writing    2 bytes at ffe6...
Writing    2 bytes at fffe...
Done, 15528 bytes total
/home/maribu/Repos/software/RIOT/msp430-cleanup/dist/tools/pyterm/pyterm -p "/dev/ttyUSB0" -b "115200"  
2023-06-15 15:00:35,527 # Connect to serial port /dev/ttyUSB0
Welcome to pyterm!
Type '/exit' to exit.
2023-06-15 15:00:36,563 # main(): This is RIOT! (Version: 2023.07-devel-621-g6e743f-msp430-cleanup)
2023-06-15 15:00:36,563 # Welcome to RIOT!
> help
2023-06-15 15:00:40,158 # help
2023-06-15 15:00:40,162 # Command              Description
2023-06-15 15:00:40,166 # ---------------------------------------
2023-06-15 15:00:40,172 # pm                   interact with layered PM subsystem
2023-06-15 15:00:40,178 # ps                   Prints information about running threads.
2023-06-15 15:00:40,182 # reboot               Reboot the node
2023-06-15 15:00:40,189 # saul                 interact with sensors and actuators using SAUL
2023-06-15 15:00:40,194 # version              Prints current RIOT_VERSION
> version
2023-06-15 15:00:43,807 # version
2023-06-15 15:00:43,812 # 2023.07-devel-621-g6e743f-msp430-cleanup
> saul
2023-06-15 15:00:44,719 # saul
2023-06-15 15:00:44,721 # No devices found

examples/default on olimex-msp430-h2618:


$ ~/Repos/software/RIOT/msp430-cleanup/examples/default % make BOARD=olimex-msp430-h2618 flash term
Building application "default" for "olimex-msp430-h2618" with MCU "msp430_f2xx_g2xx".

[...]
   text	  data	   bss	   dec	   hex	filename
  14900	   178	  1132	 16210	  3f52	/home/maribu/Repos/software/RIOT/msp430-cleanup/examples/default/bin/olimex-msp430-h2618/default.elf
mspdebug -j olimex "prog /home/maribu/Repos/software/RIOT/msp430-cleanup/examples/default/bin/olimex-msp430-h2618/default.hex"
MSPDebug version 0.25 - debugging tool for MSP430 MCUs
Copyright (C) 2009-2017 Daniel Beer <dlbeer@gmail.com>
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Chip info database from MSP430.dll v3.3.1.4 Copyright (C) 2013 TI, Inc.

Resetting Olimex command processor...
Initializing FET...
FET protocol version is 20000007
Set Vcc: 3000 mV
Configured for JTAG (2)
Sending reset...
fet: FET returned error code 11 (Could not reset device)
warning: fet: reset failed
Using Olimex identification procedure
Device ID: 0xf26f
  Code start address: 0x3100
  Code size         : 118528 byte = 115 kb
  RAM  start address: 0x200
  RAM  end   address: 0x9ff
  RAM  size         : 2048 byte = 2 kb
Device: MSP430F2618
Number of breakpoints: 8
fet: FET returned error code 34 (Not supported by selected interface or interface is not initialized)
fet: warning: message C_IDENT3 failed
fet: FET returned NAK
warning: device does not support power profiling
Chip ID data:
  ver_id:         6ff2
  ver_sub_id:     0000
  revision:       07
  fab:            60
  self:           0000
  config:         00
  fuses:          00
Device: MSP430F2619
Erasing...
Programming...
Writing 4096 bytes at 3100...
Writing 4096 bytes at 4100...
Writing 4096 bytes at 5100...
Writing 2786 bytes at 6100...
Writing    2 bytes at ffee...
Writing    2 bytes at fffe...
Done, 15078 bytes total
/home/maribu/Repos/software/RIOT/msp430-cleanup/dist/tools/pyterm/pyterm -p "/dev/ttyUSB0" -b "115200"  
2023-06-15 15:04:03,211 # Connect to serial port /dev/ttyUSB0
Welcome to pyterm!
Type '/exit' to exit.
2023-06-15 15:04:04,242 # main(): This is RIOT! (Version: 2023.07-devel-621-g6e743f-msp430-cleanup)
2023-06-15 15:04:04,242 # Welcome to RIOT!
> help
2023-06-15 15:04:07,210 # help
2023-06-15 15:04:07,213 # Command              Description
2023-06-15 15:04:07,216 # ---------------------------------------
2023-06-15 15:04:07,221 # pm                   interact with layered PM subsystem
2023-06-15 15:04:07,226 # ps                   Prints information about running threads.
2023-06-15 15:04:07,229 # reboot               Reboot the node
2023-06-15 15:04:07,235 # saul                 interact with sensors and actuators using SAUL
2023-06-15 15:04:07,240 # version              Prints current RIOT_VERSION
> saul
2023-06-15 15:04:08,649 # saul
2023-06-15 15:04:08,650 # No devices found
> version
2023-06-15 15:04:09,744 # version
2023-06-15 15:04:09,747 # 2023.07-devel-621-g6e743f-msp430-cleanup
> reboot
2023-06-15 15:04:12,115 # reboot�ain(): This is RIOT! (Version: 2023.07-devel-621-g6e743f-msp430-cleanup)
2023-06-15 15:04:12,117 # Welcome to RIOT!

Size comparisons:

# master, olimex-msp430-h2618
   text	  data	   bss	   dec	   hex	filename
  14836	   178	  1132	 16146	  3f12	/home/maribu/Repos/software/RIOT/master/examples/default/bin/olimex-msp430-h2618/default.elf
# pr, olimex-msp430-h2618
   text	  data	   bss	   dec	   hex	filename
  14836	   178	  1132	 16146	  3f12	/home/maribu/Repos/software/RIOT/msp430-cleanup/examples/default/bin/olimex-msp430-h2618/default.elf
# master, olimex-msp430-h1611
   text	  data	   bss	   dec	   hex	filename
  15274	   190	  1132	 16596	  40d4	/home/maribu/Repos/software/RIOT/master/examples/default/bin/olimex-msp430-h1611/default.elf
# pr, olimex-msp430-h1611
   text	  data	   bss	   dec	   hex	filename
  15274	   190	  1132	 16596	  40d4	/home/maribu/Repos/software/RIOT/msp430-cleanup/examples/default/bin/olimex-msp430-h1611/default.elf

@maribu maribu removed the State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet label Jun 15, 2023
@maribu maribu added the CI: no fast fail don't abort PR build after first error label Jun 19, 2023
@github-actions github-actions bot added the Area: CI Area: Continuous Integration of RIOT components label Jun 19, 2023
@maribu maribu force-pushed the msp430-cleanup branch 4 times, most recently from a425dea to b6b0e0c Compare June 19, 2023 14:44
RIOT supports two distinct families of the MSP430: The [MSP430 x1xx]
MCU family and the [MSP430 F2xx/G2xx] MCU family. For both incompatible
MCU families the code was located in the msp430fxyz folder, resulting
in case of the UART driver in particularly bizarre code looking roughly
like this:

    #ifndef UART_USE_USCI
    /* implementation of x1xx peripheral ... */
    #else
    /* implementation of F2xx/G2xx peripheral ... */
    #endif
    /* zero shared code between both variants */

This splits the peripheral drivers for USCI and USART serial IP blocks
into separate files and relocates everything in cpu/msp430, similar to
how cpu/stm32 is organized.

[MSP430 x1xx]: https://www.ti.com/lit/ug/slau049f/slau049f.pdf
[MSP430 F2xx/G2xx]: https://www.ti.com/lit/ug/slau144k/slau144k.pdf
@maribu maribu removed CI: full build disable CI build filter CI: no fast fail don't abort PR build after first error labels Jun 19, 2023
@maribu
Copy link
Member Author

maribu commented Jun 19, 2023

Interesting:

Persisting symbol[ timer_set_absolute ](file:///home/maribu/out.html#persisting_symbol_overview_357): old size: 38 bytes, new size: 36 bytes, delta: -2 bytes

Old source: /home/maribu/Repos/software/RIOT/master/cpu/msp430fxyz/periph/timer.c:70
New source: /home/maribu/Repos/software/RIOT/msp430-cleanup/cpu/msp430/periph/timer.c:70
Instructions unchanged

I wonder how it got 2 bytes smaller while still using the same instructions. Maybe padding.

Anyway, all diff actual diffs are the addresses to subroutine calls, branches or jumps. And this is due to different layout of the symbols in the memory map, likely due to alphabetical sorting being different now. IMO this is close enough to "binaries don't change" as it gets for such a mayor restructuring.

@maribu maribu removed the State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet label Jun 19, 2023
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.

please drop 7f37763

The MSP430 vendor files already provide macros containing register
constants and symbols (provided via linker scripts) containing addresses
of peripheral registers. So lets make use of that rather than
maintaining a long list of constants.
@github-actions github-actions bot removed the Area: CI Area: Continuous Integration of RIOT components label Jul 4, 2023
@maribu
Copy link
Member Author

maribu commented Jul 4, 2023

please drop 7f37763

Done. I also added a change I forgot to push that changes the GPIO driver so that indeed instructions don't change (and 6 byte .text is saved). I conducted the tests above with this state, but never did a push :/

@maribu
Copy link
Member Author

maribu commented Jul 4, 2023

bors merge

bors bot added a commit that referenced this pull request Jul 4, 2023
19733: cpu/msp430: reorganize code r=maribu a=maribu

### Contribution description

RIOT supports two distinct families of the MSP430: The [MSP430 x1xx] MCU family and the [MSP430 F2xx/G2xx] MCU family. For both incompatible MCU families the code was located in the msp430fxyz folder, resulting in case of the UART driver in particularly bizarre code looking roughly like this:

```C
#ifndef UART_USE_USCI
/* implementation of x1xx peripheral ... */
#else
/* implementation of F2xx/G2xx peripheral ... */
#endif
/* zero shared code between both variants */
```

This moves peripheral drivers shared between the two families to msp430_common and splits the SPI and UART driver into two MCU families.

In addition, it cleans up the `msp430_regs.h` by dropping most of it and using the macros and symbols provided by the vendor header files. There is little reason for us to maintain constants when TI is already doing that.

[MSP430 x1xx]: https://www.ti.com/lit/ug/slau049f/slau049f.pdf
[MSP430 F2xx/G2xx]: https://www.ti.com/lit/ug/slau144k/slau144k.pdf


19747: gnrc/ipv6/nib: reset rs_sent counter also for not-6LN interfaces r=maribu a=fabian18



Co-authored-by: Marian Buschsieweke <marian.buschsieweke@posteo.net>
Co-authored-by: Fabian Hüßler <fabian.huessler@ml-pa.com>
@maribu
Copy link
Member Author

maribu commented Jul 4, 2023

bors cancel
bors merge

@bors
Copy link
Contributor

bors bot commented Jul 4, 2023

Canceled.

bors bot added a commit that referenced this pull request Jul 4, 2023
19733: cpu/msp430: reorganize code r=maribu a=maribu

### Contribution description

RIOT supports two distinct families of the MSP430: The [MSP430 x1xx] MCU family and the [MSP430 F2xx/G2xx] MCU family. For both incompatible MCU families the code was located in the msp430fxyz folder, resulting in case of the UART driver in particularly bizarre code looking roughly like this:

```C
#ifndef UART_USE_USCI
/* implementation of x1xx peripheral ... */
#else
/* implementation of F2xx/G2xx peripheral ... */
#endif
/* zero shared code between both variants */
```

This moves peripheral drivers shared between the two families to msp430_common and splits the SPI and UART driver into two MCU families.

In addition, it cleans up the `msp430_regs.h` by dropping most of it and using the macros and symbols provided by the vendor header files. There is little reason for us to maintain constants when TI is already doing that.

[MSP430 x1xx]: https://www.ti.com/lit/ug/slau049f/slau049f.pdf
[MSP430 F2xx/G2xx]: https://www.ti.com/lit/ug/slau144k/slau144k.pdf


19747: gnrc/ipv6/nib: reset rs_sent counter also for not-6LN interfaces r=maribu a=fabian18



Co-authored-by: Marian Buschsieweke <marian.buschsieweke@posteo.net>
Co-authored-by: Fabian Hüßler <fabian.huessler@ml-pa.com>
@maribu
Copy link
Member Author

maribu commented Jul 4, 2023

bors cancel
bors merge

@bors
Copy link
Contributor

bors bot commented Jul 4, 2023

This PR was included in a batch that was canceled, it will be automatically retried

@bors
Copy link
Contributor

bors bot commented Jul 4, 2023

Canceled.

@bors
Copy link
Contributor

bors bot commented Jul 4, 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 ddf1fe2 into RIOT-OS:master Jul 4, 2023
@maribu
Copy link
Member Author

maribu commented Jul 5, 2023

🎉 thx :)

@maribu maribu deleted the msp430-cleanup branch July 5, 2023 05:10
@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: build system Area: Build system Area: cpu Area: CPU/MCU ports Area: doc Area: Documentation Area: Kconfig Area: Kconfig integration Area: sys Area: System 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: 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.

3 participants