siligent 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. siligent-0.1.0/LICENSE +202 -0
  2. siligent-0.1.0/PKG-INFO +133 -0
  3. siligent-0.1.0/README.md +113 -0
  4. siligent-0.1.0/pyproject.toml +38 -0
  5. siligent-0.1.0/setup.cfg +4 -0
  6. siligent-0.1.0/src/siligent/__init__.py +3 -0
  7. siligent-0.1.0/src/siligent/api.py +127 -0
  8. siligent-0.1.0/src/siligent/bench.py +180 -0
  9. siligent-0.1.0/src/siligent/boards/__init__.py +0 -0
  10. siligent-0.1.0/src/siligent/boards/renode/stm32l476rg.repl +41 -0
  11. siligent-0.1.0/src/siligent/boards/stm32l476rg.toml +92 -0
  12. siligent-0.1.0/src/siligent/cli.py +73 -0
  13. siligent-0.1.0/src/siligent/detect.py +84 -0
  14. siligent-0.1.0/src/siligent/errors.py +32 -0
  15. siligent-0.1.0/src/siligent/image.py +93 -0
  16. siligent-0.1.0/src/siligent/log.py +25 -0
  17. siligent-0.1.0/src/siligent/mcp_server.py +89 -0
  18. siligent-0.1.0/src/siligent/meters/__init__.py +5 -0
  19. siligent-0.1.0/src/siligent/meters/base.py +58 -0
  20. siligent-0.1.0/src/siligent/meters/ina219.py +88 -0
  21. siligent-0.1.0/src/siligent/probes/__init__.py +6 -0
  22. siligent-0.1.0/src/siligent/probes/base.py +35 -0
  23. siligent-0.1.0/src/siligent/probes/guarded.py +143 -0
  24. siligent-0.1.0/src/siligent/probes/pyocd_backend.py +91 -0
  25. siligent-0.1.0/src/siligent/probes/renode_backend.py +190 -0
  26. siligent-0.1.0/src/siligent/rules.py +150 -0
  27. siligent-0.1.0/src/siligent/runner.py +134 -0
  28. siligent-0.1.0/src/siligent/safety.py +173 -0
  29. siligent-0.1.0/src/siligent.egg-info/PKG-INFO +133 -0
  30. siligent-0.1.0/src/siligent.egg-info/SOURCES.txt +38 -0
  31. siligent-0.1.0/src/siligent.egg-info/dependency_links.txt +1 -0
  32. siligent-0.1.0/src/siligent.egg-info/entry_points.txt +3 -0
  33. siligent-0.1.0/src/siligent.egg-info/requires.txt +8 -0
  34. siligent-0.1.0/src/siligent.egg-info/top_level.txt +1 -0
  35. siligent-0.1.0/tests/test_drivers.py +60 -0
  36. siligent-0.1.0/tests/test_guarded_probe.py +87 -0
  37. siligent-0.1.0/tests/test_meters.py +35 -0
  38. siligent-0.1.0/tests/test_renode.py +49 -0
  39. siligent-0.1.0/tests/test_runner.py +92 -0
  40. siligent-0.1.0/tests/test_safety.py +143 -0
siligent-0.1.0/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,133 @@
1
+ Metadata-Version: 2.4
2
+ Name: siligent
3
+ Version: 0.1.0
4
+ Summary: Lets AI agents flash, test and measure real microcontroller boards, behind safety rules.
5
+ Author: Uwa Uwa Agbai
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/uwaagbai1/siligent
8
+ Project-URL: Issues, https://github.com/uwaagbai1/siligent/issues
9
+ Keywords: embedded,stm32,ai-agents,mcp,hardware-in-the-loop
10
+ Requires-Python: >=3.11
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Requires-Dist: pyocd>=0.36
14
+ Requires-Dist: mcp>=2.0
15
+ Provides-Extra: ina219
16
+ Requires-Dist: smbus2>=0.4; extra == "ina219"
17
+ Provides-Extra: dev
18
+ Requires-Dist: pytest>=8; extra == "dev"
19
+ Dynamic: license-file
20
+
21
+ # Siligent
22
+
23
+ An open-source framework that lets AI coding agents flash, test and measure
24
+ real microcontroller boards, behind safety rules, so a firmware change is
25
+ proven on the chip, not just compiled.
26
+
27
+ ## Try it in a minute (no hardware)
28
+
29
+ ```sh
30
+ python3 -m venv .venv && .venv/bin/pip install -e ".[dev]"
31
+ nice -n 19 make -j3 -C firmware/l476 # needs arm-none-eabi-gcc
32
+ .venv/bin/python scripts/demo.py # needs Renode, see "Virtual board"
33
+ ```
34
+
35
+ ## Status: early alpha, working on a real NUCLEO-L476RG
36
+
37
+ One board so far (STM32L476RG over ST-LINK). Expect the interfaces to change.
38
+
39
+ - Detects the ST-LINK by USB ID and the chip by its device ID, then loads that board's rules.
40
+ - Flashes through a safety gate; refusals say which rule fired and why.
41
+ - Runs on-device tests and reports pass/fail and CPU cycles per test.
42
+ - Backs up flash before every write; `siligent restore` puts a backup back.
43
+ - Logs every action, allowed or refused.
44
+ - MCP server so agents (Claude Code, Cursor, others) can use all of the above.
45
+
46
+ Not done yet: energy numbers on real hardware. Two meter drivers are written
47
+ and unit-tested but have not run on a real meter: the INA219 (active current
48
+ only) and the Nordic PPK2 (down to sub-microamp, see `plugins/siligent-ppk2`,
49
+ a separate GPL-2.0 package because its library is GPL).
50
+
51
+ Meters are plugins: a package registers a factory under the
52
+ `siligent.meters` entry-point group. When a meter powers the board, the core
53
+ checks the voltage against the board's supply range before any plugin runs.
54
+
55
+ ## Virtual board (Renode)
56
+
57
+ Add `--virtual` to any command to use a simulated L476 instead of real
58
+ hardware (agent tools take `virtual: true`). The same safety rules apply.
59
+
60
+ ```sh
61
+ .venv/bin/siligent --virtual test firmware/l476/build/tests.elf
62
+ ```
63
+
64
+ - Needs [Renode](https://github.com/renode/renode/releases) (tested with
65
+ 1.17.0). It is found on PATH, in `~/.local/opt/renode-*/`, or via `RENODE=`.
66
+ - Renode has no STM32L4 model, so `src/siligent/boards/renode/stm32l476rg.repl`
67
+ describes the core, cycle counter, flash, SRAM and ID registers. Peripherals
68
+ are not modelled yet.
69
+ - Cycle counts are simulated: within about 10-30% of the real chip for the
70
+ example tests (the real chip is slower, mostly flash wait states). No energy.
71
+
72
+ ## Quick start
73
+
74
+ ```sh
75
+ python3 -m venv .venv
76
+ .venv/bin/pip install -e ".[dev]"
77
+ .venv/bin/pyocd pack install stm32l476rg
78
+ nice -n 19 make -j3 -C firmware/l476
79
+ cp bench.example.toml bench.toml # then set flash_allowed = true when the bench is safe to flash
80
+
81
+ .venv/bin/siligent detect
82
+ .venv/bin/siligent test firmware/l476/build/tests.elf
83
+ .venv/bin/siligent flash firmware/l476/build/demo_refused.elf # refused on purpose
84
+ .venv/bin/siligent log
85
+ ```
86
+
87
+ Every command prints JSON. Other commands: `rules`, `check` (image checks
88
+ without hardware), `read`, `write`, `restore`.
89
+
90
+ Agent access (MCP, stdio): run `siligent-mcp`. Tools: `detect_hardware`,
91
+ `board_rules`, `check_image`, `flash`, `run_tests`, `read_memory`,
92
+ `write_memory`, `action_log`.
93
+
94
+ ## What the safety gate enforces (NUCLEO-L476RG)
95
+
96
+ Rules live in `src/siligent/boards/stm32l476rg.toml`.
97
+
98
+ - Flash only after a person confirms the bench is safe to flash (`flash_allowed = true` in `bench.toml`).
99
+ - Flash only if the chip matches the rules (device ID 0x415) and read protection is level 0.
100
+ - Firmware must sit inside flash, start with a valid vector table, and must not
101
+ contain the option-byte unlock keys (heuristic: catches firmware that could lock the chip).
102
+ - Host writes only to RAM, peripherals and core debug registers; never to the
103
+ flash controller, option bytes or OTP.
104
+ - SWD pins (PA13, PA14) cannot be switched out of debug mode by a host write.
105
+ - The core is halted (with a reset) before erasing: erasing under running
106
+ firmware locks the core up.
107
+
108
+ ## Writing on-device tests
109
+
110
+ See `firmware/l476/tests.c`:
111
+
112
+ ```c
113
+ #include "bp_test.h"
114
+ BP_TEST(my_test) { BP_ASSERT_EQ(add(2, 2), 4); }
115
+ ```
116
+
117
+ Results go to a RAM mailbox (`bp_results`) that the host reads after the run.
118
+
119
+ ## Tests
120
+
121
+ ```sh
122
+ .venv/bin/pytest -q
123
+ ```
124
+
125
+ The virtual-board tests skip if Renode or the built firmware is missing. Set
126
+ `SILIGENT_REQUIRE_RENODE=1` to make them fail instead, as CI does. CI
127
+ (`.github/workflows/ci.yml`) runs the unit tests on Python 3.11-3.13 and runs
128
+ the example firmware on the virtual board.
129
+
130
+ ## Licence
131
+
132
+ Apache-2.0 (see `LICENSE`). The PPK2 plugin in `plugins/siligent-ppk2` is a
133
+ separate package under GPL-2.0, because the library it uses is GPL-2.0.
@@ -0,0 +1,113 @@
1
+ # Siligent
2
+
3
+ An open-source framework that lets AI coding agents flash, test and measure
4
+ real microcontroller boards, behind safety rules, so a firmware change is
5
+ proven on the chip, not just compiled.
6
+
7
+ ## Try it in a minute (no hardware)
8
+
9
+ ```sh
10
+ python3 -m venv .venv && .venv/bin/pip install -e ".[dev]"
11
+ nice -n 19 make -j3 -C firmware/l476 # needs arm-none-eabi-gcc
12
+ .venv/bin/python scripts/demo.py # needs Renode, see "Virtual board"
13
+ ```
14
+
15
+ ## Status: early alpha, working on a real NUCLEO-L476RG
16
+
17
+ One board so far (STM32L476RG over ST-LINK). Expect the interfaces to change.
18
+
19
+ - Detects the ST-LINK by USB ID and the chip by its device ID, then loads that board's rules.
20
+ - Flashes through a safety gate; refusals say which rule fired and why.
21
+ - Runs on-device tests and reports pass/fail and CPU cycles per test.
22
+ - Backs up flash before every write; `siligent restore` puts a backup back.
23
+ - Logs every action, allowed or refused.
24
+ - MCP server so agents (Claude Code, Cursor, others) can use all of the above.
25
+
26
+ Not done yet: energy numbers on real hardware. Two meter drivers are written
27
+ and unit-tested but have not run on a real meter: the INA219 (active current
28
+ only) and the Nordic PPK2 (down to sub-microamp, see `plugins/siligent-ppk2`,
29
+ a separate GPL-2.0 package because its library is GPL).
30
+
31
+ Meters are plugins: a package registers a factory under the
32
+ `siligent.meters` entry-point group. When a meter powers the board, the core
33
+ checks the voltage against the board's supply range before any plugin runs.
34
+
35
+ ## Virtual board (Renode)
36
+
37
+ Add `--virtual` to any command to use a simulated L476 instead of real
38
+ hardware (agent tools take `virtual: true`). The same safety rules apply.
39
+
40
+ ```sh
41
+ .venv/bin/siligent --virtual test firmware/l476/build/tests.elf
42
+ ```
43
+
44
+ - Needs [Renode](https://github.com/renode/renode/releases) (tested with
45
+ 1.17.0). It is found on PATH, in `~/.local/opt/renode-*/`, or via `RENODE=`.
46
+ - Renode has no STM32L4 model, so `src/siligent/boards/renode/stm32l476rg.repl`
47
+ describes the core, cycle counter, flash, SRAM and ID registers. Peripherals
48
+ are not modelled yet.
49
+ - Cycle counts are simulated: within about 10-30% of the real chip for the
50
+ example tests (the real chip is slower, mostly flash wait states). No energy.
51
+
52
+ ## Quick start
53
+
54
+ ```sh
55
+ python3 -m venv .venv
56
+ .venv/bin/pip install -e ".[dev]"
57
+ .venv/bin/pyocd pack install stm32l476rg
58
+ nice -n 19 make -j3 -C firmware/l476
59
+ cp bench.example.toml bench.toml # then set flash_allowed = true when the bench is safe to flash
60
+
61
+ .venv/bin/siligent detect
62
+ .venv/bin/siligent test firmware/l476/build/tests.elf
63
+ .venv/bin/siligent flash firmware/l476/build/demo_refused.elf # refused on purpose
64
+ .venv/bin/siligent log
65
+ ```
66
+
67
+ Every command prints JSON. Other commands: `rules`, `check` (image checks
68
+ without hardware), `read`, `write`, `restore`.
69
+
70
+ Agent access (MCP, stdio): run `siligent-mcp`. Tools: `detect_hardware`,
71
+ `board_rules`, `check_image`, `flash`, `run_tests`, `read_memory`,
72
+ `write_memory`, `action_log`.
73
+
74
+ ## What the safety gate enforces (NUCLEO-L476RG)
75
+
76
+ Rules live in `src/siligent/boards/stm32l476rg.toml`.
77
+
78
+ - Flash only after a person confirms the bench is safe to flash (`flash_allowed = true` in `bench.toml`).
79
+ - Flash only if the chip matches the rules (device ID 0x415) and read protection is level 0.
80
+ - Firmware must sit inside flash, start with a valid vector table, and must not
81
+ contain the option-byte unlock keys (heuristic: catches firmware that could lock the chip).
82
+ - Host writes only to RAM, peripherals and core debug registers; never to the
83
+ flash controller, option bytes or OTP.
84
+ - SWD pins (PA13, PA14) cannot be switched out of debug mode by a host write.
85
+ - The core is halted (with a reset) before erasing: erasing under running
86
+ firmware locks the core up.
87
+
88
+ ## Writing on-device tests
89
+
90
+ See `firmware/l476/tests.c`:
91
+
92
+ ```c
93
+ #include "bp_test.h"
94
+ BP_TEST(my_test) { BP_ASSERT_EQ(add(2, 2), 4); }
95
+ ```
96
+
97
+ Results go to a RAM mailbox (`bp_results`) that the host reads after the run.
98
+
99
+ ## Tests
100
+
101
+ ```sh
102
+ .venv/bin/pytest -q
103
+ ```
104
+
105
+ The virtual-board tests skip if Renode or the built firmware is missing. Set
106
+ `SILIGENT_REQUIRE_RENODE=1` to make them fail instead, as CI does. CI
107
+ (`.github/workflows/ci.yml`) runs the unit tests on Python 3.11-3.13 and runs
108
+ the example firmware on the virtual board.
109
+
110
+ ## Licence
111
+
112
+ Apache-2.0 (see `LICENSE`). The PPK2 plugin in `plugins/siligent-ppk2` is a
113
+ separate package under GPL-2.0, because the library it uses is GPL-2.0.
@@ -0,0 +1,38 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "siligent"
7
+ version = "0.1.0"
8
+ description = "Lets AI agents flash, test and measure real microcontroller boards, behind safety rules."
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ license = "Apache-2.0"
12
+ authors = [{ name = "Uwa Uwa Agbai" }]
13
+ keywords = ["embedded", "stm32", "ai-agents", "mcp", "hardware-in-the-loop"]
14
+ dependencies = [
15
+ "pyocd>=0.36",
16
+ "mcp>=2.0",
17
+ ]
18
+
19
+ [project.optional-dependencies]
20
+ ina219 = ["smbus2>=0.4"]
21
+ dev = ["pytest>=8"]
22
+
23
+ [project.urls]
24
+ Homepage = "https://github.com/uwaagbai1/siligent"
25
+ Issues = "https://github.com/uwaagbai1/siligent/issues"
26
+
27
+ [project.scripts]
28
+ siligent = "siligent.cli:main"
29
+ siligent-mcp = "siligent.mcp_server:main"
30
+
31
+ [tool.setuptools.packages.find]
32
+ where = ["src"]
33
+
34
+ [tool.setuptools.package-data]
35
+ siligent = ["boards/*.toml", "boards/renode/*.repl"]
36
+
37
+ [tool.pytest.ini_options]
38
+ testpaths = ["tests"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,3 @@
1
+ """Siligent: safe, measured access to real hardware for AI agents."""
2
+
3
+ __version__ = "0.1.0"
@@ -0,0 +1,127 @@
1
+ """Plain functions shared by the CLI and the MCP server. Each returns a JSON-ready dict."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from .bench import Bench, BenchConfig
6
+ from .detect import scan_meters, scan_usb
7
+ from .errors import SiligentError, SafetyRefusal
8
+ from .image import load_image
9
+ from .rules import load_rules
10
+ from .runner import run_tests as _run_tests
11
+ from .safety import BenchState, SafetyGate
12
+
13
+
14
+ def _guard(fn):
15
+ """Turn refusals and errors into structured results an agent can act on."""
16
+
17
+ def wrapper(*args, **kwargs):
18
+ try:
19
+ return fn(*args, **kwargs)
20
+ except SafetyRefusal as e:
21
+ return e.to_dict()
22
+ except SiligentError as e:
23
+ return {"ok": False, "error": str(e)}
24
+ except Exception as e: # hardware and library errors: report, don't crash the agent's tool call
25
+ return {"ok": False, "error": f"{type(e).__name__}: {e}"}
26
+
27
+ wrapper.__name__ = fn.__name__
28
+ wrapper.__doc__ = fn.__doc__
29
+ return wrapper
30
+
31
+
32
+ @_guard
33
+ def detect(config: BenchConfig | None = None, connect: bool = True) -> dict:
34
+ """List debug probes and, for supported ones, identify the board and its rules."""
35
+ probes = [p.to_dict() for p in scan_usb()]
36
+ result: dict = {"ok": True, "probes": probes, "meters": scan_meters()}
37
+ if connect and any(p["supported"] for p in probes):
38
+ try:
39
+ with Bench(config) as bench:
40
+ result["board"] = {
41
+ "name": bench.rules.name,
42
+ "chip": bench.rules.chip,
43
+ "dev_id": hex(bench.probe.device_id()),
44
+ "probe_uid": bench.probe.backend.unique_id,
45
+ "rules": bench.rules.source,
46
+ }
47
+ except SafetyRefusal as e:
48
+ result["board"] = e.to_dict()
49
+ return result
50
+
51
+
52
+ @_guard
53
+ def rules(board: str = "stm32l476rg") -> dict:
54
+ """Show the safety rules for a board."""
55
+ return {"ok": True, **load_rules(board).summary()}
56
+
57
+
58
+ @_guard
59
+ def check_image(path: str, board: str = "stm32l476rg", config: BenchConfig | None = None) -> dict:
60
+ """Check a firmware image against a board's rules without touching hardware."""
61
+ cfg = config or BenchConfig.load()
62
+ image = load_image(path)
63
+ gate = SafetyGate(load_rules(cfg.board or board), BenchState(cfg.flash_allowed))
64
+ gate.check_image(image)
65
+ return {"ok": True, "image": path, "sha256": image.sha256, "bytes": image.size, "detail": "passes image checks"}
66
+
67
+
68
+ @_guard
69
+ def flash(path: str, config: BenchConfig | None = None) -> dict:
70
+ """Flash a firmware image through the safety gate."""
71
+ with Bench(config) as bench:
72
+ return bench.probe.flash(load_image(path))
73
+
74
+
75
+ @_guard
76
+ def restore(path: str, config: BenchConfig | None = None) -> dict:
77
+ """Put a saved full-flash snapshot (raw .bin from the start of flash) back on the chip.
78
+
79
+ The same safety checks apply as for any flash. Trailing erased bytes are skipped.
80
+ """
81
+ from pathlib import Path
82
+
83
+ from .image import Image, Segment
84
+
85
+ raw = Path(path).read_bytes().rstrip(b"\xff")
86
+ raw += b"\xff" * (-len(raw) % 8) # flash programs in 8-byte double words
87
+ with Bench(config) as bench:
88
+ image = Image(path, [Segment(bench.rules.flash.start, raw)])
89
+ return bench.probe.flash(image)
90
+
91
+
92
+ @_guard
93
+ def run_tests(path: str, timeout_s: float = 10.0, config: BenchConfig | None = None) -> dict:
94
+ """Flash test firmware, run it, and return pass/fail, cycles and energy."""
95
+ with Bench(config) as bench:
96
+ return _run_tests(bench.probe, load_image(path), meter=bench.meter, timeout_s=timeout_s)
97
+
98
+
99
+ @_guard
100
+ def read_memory(address: int, length: int, config: BenchConfig | None = None) -> dict:
101
+ """Read memory from the chip."""
102
+ if not 0 < length <= 4096:
103
+ raise SiligentError("length must be between 1 and 4096 bytes")
104
+ with Bench(config) as bench:
105
+ data, halted = bench.probe.read_memory_checked(address, length)
106
+ out = {"ok": True, "address": hex(address), "length": length, "hex": data.hex()}
107
+ if halted:
108
+ out["note"] = "the core was asleep, so it was halted briefly for this read and then resumed"
109
+ return out
110
+
111
+
112
+ @_guard
113
+ def write_memory(address: int, data_hex: str, config: BenchConfig | None = None) -> dict:
114
+ """Write bytes to RAM or a peripheral register, subject to the board's rules."""
115
+ data = bytes.fromhex(data_hex)
116
+ with Bench(config) as bench:
117
+ bench.probe.write_memory(address, data)
118
+ return {"ok": True, "address": hex(address), "length": len(data)}
119
+
120
+
121
+ @_guard
122
+ def action_log(n: int = 20, config: BenchConfig | None = None) -> dict:
123
+ """The most recent bench actions, allowed and refused."""
124
+ cfg = config or BenchConfig.load()
125
+ from .log import ActionLog
126
+
127
+ return {"ok": True, "entries": ActionLog(cfg.log_path).tail(n)}