aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorFelipe Balbi <[email protected]>2025-11-13 13:17:44 -0800
committerGitHub <[email protected]>2025-11-13 13:17:44 -0800
commit77b2c602a60e41c7c977003a6d40367ac285930e (patch)
tree6a6490c883f84658c992af4351b8d8a8d8e1c1e4 /examples
parentf4b8ae36bec40a15bedd3c0493e4822f9c5238dd (diff)
Move examples to a package of their own (#16)
* Move examples to a package of their own * cargo +nightly fmt * Add missing safety doc * cargo clippy examples * fmt again --------- Co-authored-by: Felipe Balbi <[email protected]>
Diffstat (limited to 'examples')
-rw-r--r--examples/.cargo/config.toml17
-rw-r--r--examples/.gitignore1
-rw-r--r--examples/Cargo.lock625
-rw-r--r--examples/Cargo.toml21
-rw-r--r--examples/build.rs20
-rw-r--r--examples/memory.x5
-rw-r--r--examples/src/bin/adc_interrupt.rs (renamed from examples/adc_interrupt.rs)21
-rw-r--r--examples/src/bin/adc_polling.rs (renamed from examples/adc_polling.rs)23
-rw-r--r--examples/src/bin/blink.rs (renamed from examples/blink.rs)16
-rw-r--r--examples/src/bin/hello.rs (renamed from examples/hello.rs)13
-rw-r--r--examples/src/bin/lpuart_buffered.rs (renamed from examples/lpuart_buffered.rs)17
-rw-r--r--examples/src/bin/lpuart_polling.rs (renamed from examples/lpuart_polling.rs)10
-rw-r--r--examples/src/bin/ostimer_alarm.rs (renamed from examples/ostimer_alarm.rs)15
-rw-r--r--examples/src/bin/ostimer_async.rs (renamed from examples/ostimer_async.rs)17
-rw-r--r--examples/src/bin/ostimer_counter.rs (renamed from examples/ostimer_counter.rs)11
-rw-r--r--examples/src/bin/ostimer_race_test.rs (renamed from examples/ostimer_race_test.rs)13
-rw-r--r--examples/src/bin/rtc_alarm.rs (renamed from examples/rtc_alarm.rs)11
-rw-r--r--examples/src/bin/uart_interrupt.rs (renamed from examples/uart_interrupt.rs)11
-rw-r--r--examples/src/common/mod.rs (renamed from examples/common/mod.rs)10
-rw-r--r--examples/src/lib.rs63
20 files changed, 826 insertions, 114 deletions
diff --git a/examples/.cargo/config.toml b/examples/.cargo/config.toml
new file mode 100644
index 000000000..ecb11be64
--- /dev/null
+++ b/examples/.cargo/config.toml
@@ -0,0 +1,17 @@
1[target.thumbv8m.main-none-eabihf]
2runner = 'probe-rs run --chip MCXA276 --preverify --verify'
3
4rustflags = [
5 "-C", "linker=flip-link",
6 "-C", "link-arg=-Tlink.x",
7 "-C", "link-arg=-Tdefmt.x",
8 # This is needed if your flash or ram addresses are not aligned to 0x10000 in memory.x
9 # See https://github.com/rust-embedded/cortex-m-quickstart/pull/95
10 "-C", "link-arg=--nmagic",
11]
12
13[build]
14target = "thumbv8m.main-none-eabihf" # Cortex-M33
15
16[env]
17DEFMT_LOG = "trace"
diff --git a/examples/.gitignore b/examples/.gitignore
new file mode 100644
index 000000000..2f7896d1d
--- /dev/null
+++ b/examples/.gitignore
@@ -0,0 +1 @@
target/
diff --git a/examples/Cargo.lock b/examples/Cargo.lock
new file mode 100644
index 000000000..b774aff97
--- /dev/null
+++ b/examples/Cargo.lock
@@ -0,0 +1,625 @@
1# This file is automatically @generated by Cargo.
2# It is not intended for manual editing.
3version = 4
4
5[[package]]
6name = "autocfg"
7version = "1.5.0"
8source = "registry+https://github.com/rust-lang/crates.io-index"
9checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
10
11[[package]]
12name = "bare-metal"
13version = "0.2.5"
14source = "registry+https://github.com/rust-lang/crates.io-index"
15checksum = "5deb64efa5bd81e31fcd1938615a6d98c82eafcbcd787162b6f63b91d6bac5b3"
16dependencies = [
17 "rustc_version",
18]
19
20[[package]]
21name = "bitfield"
22version = "0.13.2"
23source = "registry+https://github.com/rust-lang/crates.io-index"
24checksum = "46afbd2983a5d5a7bd740ccb198caf5b82f45c40c09c0eed36052d91cb92e719"
25
26[[package]]
27name = "bitflags"
28version = "1.3.2"
29source = "registry+https://github.com/rust-lang/crates.io-index"
30checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
31
32[[package]]
33name = "byteorder"
34version = "1.5.0"
35source = "registry+https://github.com/rust-lang/crates.io-index"
36checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
37
38[[package]]
39name = "cfg-if"
40version = "1.0.4"
41source = "registry+https://github.com/rust-lang/crates.io-index"
42checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
43
44[[package]]
45name = "cortex-m"
46version = "0.7.7"
47source = "registry+https://github.com/rust-lang/crates.io-index"
48checksum = "8ec610d8f49840a5b376c69663b6369e71f4b34484b9b2eb29fb918d92516cb9"
49dependencies = [
50 "bare-metal",
51 "bitfield",
52 "critical-section",
53 "embedded-hal 0.2.7",
54 "volatile-register",
55]
56
57[[package]]
58name = "cortex-m-rt"
59version = "0.7.5"
60source = "registry+https://github.com/rust-lang/crates.io-index"
61checksum = "801d4dec46b34c299ccf6b036717ae0fce602faa4f4fe816d9013b9a7c9f5ba6"
62dependencies = [
63 "cortex-m-rt-macros",
64]
65
66[[package]]
67name = "cortex-m-rt-macros"
68version = "0.7.5"
69source = "registry+https://github.com/rust-lang/crates.io-index"
70checksum = "e37549a379a9e0e6e576fd208ee60394ccb8be963889eebba3ffe0980364f472"
71dependencies = [
72 "proc-macro2",
73 "quote",
74 "syn",
75]
76
77[[package]]
78name = "critical-section"
79version = "1.2.0"
80source = "registry+https://github.com/rust-lang/crates.io-index"
81checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b"
82
83[[package]]
84name = "darling"
85version = "0.20.11"
86source = "registry+https://github.com/rust-lang/crates.io-index"
87checksum = "fc7f46116c46ff9ab3eb1597a45688b6715c6e628b5c133e288e709a29bcb4ee"
88dependencies = [
89 "darling_core",
90 "darling_macro",
91]
92
93[[package]]
94name = "darling_core"
95version = "0.20.11"
96source = "registry+https://github.com/rust-lang/crates.io-index"
97checksum = "0d00b9596d185e565c2207a0b01f8bd1a135483d02d9b7b0a54b11da8d53412e"
98dependencies = [
99 "fnv",
100 "ident_case",
101 "proc-macro2",
102 "quote",
103 "strsim",
104 "syn",
105]
106
107[[package]]
108name = "darling_macro"
109version = "0.20.11"
110source = "registry+https://github.com/rust-lang/crates.io-index"
111checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead"
112dependencies = [
113 "darling_core",
114 "quote",
115 "syn",
116]
117
118[[package]]
119name = "defmt"
120version = "1.0.1"
121source = "registry+https://github.com/rust-lang/crates.io-index"
122checksum = "548d977b6da32fa1d1fda2876453da1e7df63ad0304c8b3dae4dbe7b96f39b78"
123dependencies = [
124 "bitflags",
125 "defmt-macros",
126]
127
128[[package]]
129name = "defmt-macros"
130version = "1.0.1"
131source = "registry+https://github.com/rust-lang/crates.io-index"
132checksum = "3d4fc12a85bcf441cfe44344c4b72d58493178ce635338a3f3b78943aceb258e"
133dependencies = [
134 "defmt-parser",
135 "proc-macro-error2",
136 "proc-macro2",
137 "quote",
138 "syn",
139]
140
141[[package]]
142name = "defmt-parser"
143version = "1.0.0"
144source = "registry+https://github.com/rust-lang/crates.io-index"
145checksum = "10d60334b3b2e7c9d91ef8150abfb6fa4c1c39ebbcf4a81c2e346aad939fee3e"
146dependencies = [
147 "thiserror",
148]
149
150[[package]]
151name = "defmt-rtt"
152version = "1.1.0"
153source = "registry+https://github.com/rust-lang/crates.io-index"
154checksum = "93d5a25c99d89c40f5676bec8cefe0614f17f0f40e916f98e345dae941807f9e"
155dependencies = [
156 "critical-section",
157 "defmt",
158]
159
160[[package]]
161name = "document-features"
162version = "0.2.12"
163source = "registry+https://github.com/rust-lang/crates.io-index"
164checksum = "d4b8a88685455ed29a21542a33abd9cb6510b6b129abadabdcef0f4c55bc8f61"
165dependencies = [
166 "litrs",
167]
168
169[[package]]
170name = "embassy-embedded-hal"
171version = "0.5.0"
172source = "registry+https://github.com/rust-lang/crates.io-index"
173checksum = "554e3e840696f54b4c9afcf28a0f24da431c927f4151040020416e7393d6d0d8"
174dependencies = [
175 "embassy-futures",
176 "embassy-hal-internal",
177 "embassy-sync",
178 "embedded-hal 0.2.7",
179 "embedded-hal 1.0.0",
180 "embedded-hal-async",
181 "embedded-storage",
182 "embedded-storage-async",
183 "nb 1.1.0",
184]
185
186[[package]]
187name = "embassy-executor"
188version = "0.9.1"
189source = "registry+https://github.com/rust-lang/crates.io-index"
190checksum = "06070468370195e0e86f241c8e5004356d696590a678d47d6676795b2e439c6b"
191dependencies = [
192 "cortex-m",
193 "critical-section",
194 "document-features",
195 "embassy-executor-macros",
196 "embassy-executor-timer-queue",
197]
198
199[[package]]
200name = "embassy-executor-macros"
201version = "0.7.0"
202source = "registry+https://github.com/rust-lang/crates.io-index"
203checksum = "dfdddc3a04226828316bf31393b6903ee162238576b1584ee2669af215d55472"
204dependencies = [
205 "darling",
206 "proc-macro2",
207 "quote",
208 "syn",
209]
210
211[[package]]
212name = "embassy-executor-timer-queue"
213version = "0.1.0"
214source = "registry+https://github.com/rust-lang/crates.io-index"
215checksum = "2fc328bf943af66b80b98755db9106bf7e7471b0cf47dc8559cd9a6be504cc9c"
216
217[[package]]
218name = "embassy-futures"
219version = "0.1.2"
220source = "registry+https://github.com/rust-lang/crates.io-index"
221checksum = "dc2d050bdc5c21e0862a89256ed8029ae6c290a93aecefc73084b3002cdebb01"
222
223[[package]]
224name = "embassy-hal-internal"
225version = "0.3.0"
226source = "registry+https://github.com/rust-lang/crates.io-index"
227checksum = "95285007a91b619dc9f26ea8f55452aa6c60f7115a4edc05085cd2bd3127cd7a"
228dependencies = [
229 "cortex-m",
230 "critical-section",
231 "num-traits",
232]
233
234[[package]]
235name = "embassy-mcxa"
236version = "0.1.0"
237dependencies = [
238 "cortex-m",
239 "cortex-m-rt",
240 "critical-section",
241 "defmt",
242 "embassy-embedded-hal",
243 "embassy-executor",
244 "embassy-hal-internal",
245 "embassy-sync",
246 "embassy-time",
247 "embassy-time-driver",
248 "embedded-hal 0.2.7",
249 "embedded-hal 1.0.0",
250 "embedded-hal-async",
251 "embedded-hal-nb",
252 "embedded-io",
253 "embedded-io-async",
254 "heapless 0.8.0",
255 "mcxa-pac",
256 "nb 1.1.0",
257 "paste",
258]
259
260[[package]]
261name = "embassy-mcxa-examples"
262version = "0.1.0"
263dependencies = [
264 "cortex-m",
265 "cortex-m-rt",
266 "critical-section",
267 "defmt",
268 "defmt-rtt",
269 "embassy-embedded-hal",
270 "embassy-executor",
271 "embassy-mcxa",
272 "embassy-sync",
273 "embassy-time",
274 "embassy-time-driver",
275 "embedded-io-async",
276 "heapless 0.9.2",
277 "panic-probe",
278]
279
280[[package]]
281name = "embassy-sync"
282version = "0.7.2"
283source = "registry+https://github.com/rust-lang/crates.io-index"
284checksum = "73974a3edbd0bd286759b3d483540f0ebef705919a5f56f4fc7709066f71689b"
285dependencies = [
286 "cfg-if",
287 "critical-section",
288 "embedded-io-async",
289 "futures-core",
290 "futures-sink",
291 "heapless 0.8.0",
292]
293
294[[package]]
295name = "embassy-time"
296version = "0.5.0"
297source = "registry+https://github.com/rust-lang/crates.io-index"
298checksum = "f4fa65b9284d974dad7a23bb72835c4ec85c0b540d86af7fc4098c88cff51d65"
299dependencies = [
300 "cfg-if",
301 "critical-section",
302 "document-features",
303 "embassy-time-driver",
304 "embedded-hal 0.2.7",
305 "embedded-hal 1.0.0",
306 "embedded-hal-async",
307 "futures-core",
308]
309
310[[package]]
311name = "embassy-time-driver"
312version = "0.2.1"
313source = "registry+https://github.com/rust-lang/crates.io-index"
314checksum = "a0a244c7dc22c8d0289379c8d8830cae06bb93d8f990194d0de5efb3b5ae7ba6"
315dependencies = [
316 "document-features",
317]
318
319[[package]]
320name = "embedded-hal"
321version = "0.2.7"
322source = "registry+https://github.com/rust-lang/crates.io-index"
323checksum = "35949884794ad573cf46071e41c9b60efb0cb311e3ca01f7af807af1debc66ff"
324dependencies = [
325 "nb 0.1.3",
326 "void",
327]
328
329[[package]]
330name = "embedded-hal"
331version = "1.0.0"
332source = "registry+https://github.com/rust-lang/crates.io-index"
333checksum = "361a90feb7004eca4019fb28352a9465666b24f840f5c3cddf0ff13920590b89"
334
335[[package]]
336name = "embedded-hal-async"
337version = "1.0.0"
338source = "registry+https://github.com/rust-lang/crates.io-index"
339checksum = "0c4c685bbef7fe13c3c6dd4da26841ed3980ef33e841cddfa15ce8a8fb3f1884"
340dependencies = [
341 "embedded-hal 1.0.0",
342]
343
344[[package]]
345name = "embedded-hal-nb"
346version = "1.0.0"
347source = "registry+https://github.com/rust-lang/crates.io-index"
348checksum = "fba4268c14288c828995299e59b12babdbe170f6c6d73731af1b4648142e8605"
349dependencies = [
350 "embedded-hal 1.0.0",
351 "nb 1.1.0",
352]
353
354[[package]]
355name = "embedded-io"
356version = "0.6.1"
357source = "registry+https://github.com/rust-lang/crates.io-index"
358checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d"
359
360[[package]]
361name = "embedded-io-async"
362version = "0.6.1"
363source = "registry+https://github.com/rust-lang/crates.io-index"
364checksum = "3ff09972d4073aa8c299395be75161d582e7629cd663171d62af73c8d50dba3f"
365dependencies = [
366 "embedded-io",
367]
368
369[[package]]
370name = "embedded-storage"
371version = "0.3.1"
372source = "registry+https://github.com/rust-lang/crates.io-index"
373checksum = "a21dea9854beb860f3062d10228ce9b976da520a73474aed3171ec276bc0c032"
374
375[[package]]
376name = "embedded-storage-async"
377version = "0.4.1"
378source = "registry+https://github.com/rust-lang/crates.io-index"
379checksum = "1763775e2323b7d5f0aa6090657f5e21cfa02ede71f5dc40eead06d64dcd15cc"
380dependencies = [
381 "embedded-storage",
382]
383
384[[package]]
385name = "fnv"
386version = "1.0.7"
387source = "registry+https://github.com/rust-lang/crates.io-index"
388checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
389
390[[package]]
391name = "futures-core"
392version = "0.3.31"
393source = "registry+https://github.com/rust-lang/crates.io-index"
394checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e"
395
396[[package]]
397name = "futures-sink"
398version = "0.3.31"
399source = "registry+https://github.com/rust-lang/crates.io-index"
400checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7"
401
402[[package]]
403name = "hash32"
404version = "0.3.1"
405source = "registry+https://github.com/rust-lang/crates.io-index"
406checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606"
407dependencies = [
408 "byteorder",
409]
410
411[[package]]
412name = "heapless"
413version = "0.8.0"
414source = "registry+https://github.com/rust-lang/crates.io-index"
415checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad"
416dependencies = [
417 "hash32",
418 "stable_deref_trait",
419]
420
421[[package]]
422name = "heapless"
423version = "0.9.2"
424source = "registry+https://github.com/rust-lang/crates.io-index"
425checksum = "2af2455f757db2b292a9b1768c4b70186d443bcb3b316252d6b540aec1cd89ed"
426dependencies = [
427 "hash32",
428 "stable_deref_trait",
429]
430
431[[package]]
432name = "ident_case"
433version = "1.0.1"
434source = "registry+https://github.com/rust-lang/crates.io-index"
435checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
436
437[[package]]
438name = "litrs"
439version = "1.0.0"
440source = "registry+https://github.com/rust-lang/crates.io-index"
441checksum = "11d3d7f243d5c5a8b9bb5d6dd2b1602c0cb0b9db1621bafc7ed66e35ff9fe092"
442
443[[package]]
444name = "mcxa-pac"
445version = "0.1.0"
446source = "git+https://github.com/OpenDevicePartnership/mcxa-pac?rev=3ab4c868f75a9240bb8fdce24982d34f2273aabf#3ab4c868f75a9240bb8fdce24982d34f2273aabf"
447dependencies = [
448 "cortex-m",
449 "cortex-m-rt",
450 "vcell",
451]
452
453[[package]]
454name = "nb"
455version = "0.1.3"
456source = "registry+https://github.com/rust-lang/crates.io-index"
457checksum = "801d31da0513b6ec5214e9bf433a77966320625a37860f910be265be6e18d06f"
458dependencies = [
459 "nb 1.1.0",
460]
461
462[[package]]
463name = "nb"
464version = "1.1.0"
465source = "registry+https://github.com/rust-lang/crates.io-index"
466checksum = "8d5439c4ad607c3c23abf66de8c8bf57ba8adcd1f129e699851a6e43935d339d"
467
468[[package]]
469name = "num-traits"
470version = "0.2.19"
471source = "registry+https://github.com/rust-lang/crates.io-index"
472checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
473dependencies = [
474 "autocfg",
475]
476
477[[package]]
478name = "panic-probe"
479version = "1.0.0"
480source = "registry+https://github.com/rust-lang/crates.io-index"
481checksum = "fd402d00b0fb94c5aee000029204a46884b1262e0c443f166d86d2c0747e1a1a"
482dependencies = [
483 "cortex-m",
484 "defmt",
485]
486
487[[package]]
488name = "paste"
489version = "1.0.15"
490source = "registry+https://github.com/rust-lang/crates.io-index"
491checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
492
493[[package]]
494name = "proc-macro-error-attr2"
495version = "2.0.0"
496source = "registry+https://github.com/rust-lang/crates.io-index"
497checksum = "96de42df36bb9bba5542fe9f1a054b8cc87e172759a1868aa05c1f3acc89dfc5"
498dependencies = [
499 "proc-macro2",
500 "quote",
501]
502
503[[package]]
504name = "proc-macro-error2"
505version = "2.0.1"
506source = "registry+https://github.com/rust-lang/crates.io-index"
507checksum = "11ec05c52be0a07b08061f7dd003e7d7092e0472bc731b4af7bb1ef876109802"
508dependencies = [
509 "proc-macro-error-attr2",
510 "proc-macro2",
511 "quote",
512 "syn",
513]
514
515[[package]]
516name = "proc-macro2"
517version = "1.0.103"
518source = "registry+https://github.com/rust-lang/crates.io-index"
519checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8"
520dependencies = [
521 "unicode-ident",
522]
523
524[[package]]
525name = "quote"
526version = "1.0.42"
527source = "registry+https://github.com/rust-lang/crates.io-index"
528checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f"
529dependencies = [
530 "proc-macro2",
531]
532
533[[package]]
534name = "rustc_version"
535version = "0.2.3"
536source = "registry+https://github.com/rust-lang/crates.io-index"
537checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
538dependencies = [
539 "semver",
540]
541
542[[package]]
543name = "semver"
544version = "0.9.0"
545source = "registry+https://github.com/rust-lang/crates.io-index"
546checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
547dependencies = [
548 "semver-parser",
549]
550
551[[package]]
552name = "semver-parser"
553version = "0.7.0"
554source = "registry+https://github.com/rust-lang/crates.io-index"
555checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
556
557[[package]]
558name = "stable_deref_trait"
559version = "1.2.1"
560source = "registry+https://github.com/rust-lang/crates.io-index"
561checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596"
562
563[[package]]
564name = "strsim"
565version = "0.11.1"
566source = "registry+https://github.com/rust-lang/crates.io-index"
567checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
568
569[[package]]
570name = "syn"
571version = "2.0.110"
572source = "registry+https://github.com/rust-lang/crates.io-index"
573checksum = "a99801b5bd34ede4cf3fc688c5919368fea4e4814a4664359503e6015b280aea"
574dependencies = [
575 "proc-macro2",
576 "quote",
577 "unicode-ident",
578]
579
580[[package]]
581name = "thiserror"
582version = "2.0.17"
583source = "registry+https://github.com/rust-lang/crates.io-index"
584checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8"
585dependencies = [
586 "thiserror-impl",
587]
588
589[[package]]
590name = "thiserror-impl"
591version = "2.0.17"
592source = "registry+https://github.com/rust-lang/crates.io-index"
593checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913"
594dependencies = [
595 "proc-macro2",
596 "quote",
597 "syn",
598]
599
600[[package]]
601name = "unicode-ident"
602version = "1.0.22"
603source = "registry+https://github.com/rust-lang/crates.io-index"
604checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
605
606[[package]]
607name = "vcell"
608version = "0.1.3"
609source = "registry+https://github.com/rust-lang/crates.io-index"
610checksum = "77439c1b53d2303b20d9459b1ade71a83c716e3f9c34f3228c00e6f185d6c002"
611
612[[package]]
613name = "void"
614version = "1.0.2"
615source = "registry+https://github.com/rust-lang/crates.io-index"
616checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
617
618[[package]]
619name = "volatile-register"
620version = "0.2.2"
621source = "registry+https://github.com/rust-lang/crates.io-index"
622checksum = "de437e2a6208b014ab52972a27e59b33fa2920d3e00fe05026167a1c509d19cc"
623dependencies = [
624 "vcell",
625]
diff --git a/examples/Cargo.toml b/examples/Cargo.toml
new file mode 100644
index 000000000..6b100de42
--- /dev/null
+++ b/examples/Cargo.toml
@@ -0,0 +1,21 @@
1[package]
2name = "embassy-mcxa-examples"
3version = "0.1.0"
4edition = "2021"
5license = "MIT OR Apache-2.0"
6
7[dependencies]
8cortex-m = { version = "0.7", features = ["critical-section-single-core"] }
9cortex-m-rt = { version = "0.7", features = ["device"] }
10critical-section = "1.2.0"
11defmt = "1.0"
12defmt-rtt = "1.0"
13embassy-embedded-hal = "0.5.0"
14embassy-executor = { version = "0.9.0", features = ["arch-cortex-m", "executor-interrupt", "executor-thread"], default-features = false }
15embassy-mcxa = { path = "../", features = ["defmt", "rt", "unstable-pac"] }
16embassy-sync = "0.7.2"
17embassy-time = "0.5.0"
18embassy-time-driver = "0.2.1"
19embedded-io-async = "0.6.1"
20heapless = "0.9.2"
21panic-probe = { version = "1.0", features = ["print-defmt"] }
diff --git a/examples/build.rs b/examples/build.rs
new file mode 100644
index 000000000..f076bba9f
--- /dev/null
+++ b/examples/build.rs
@@ -0,0 +1,20 @@
1use std::env;
2use std::fs::File;
3use std::io::Write;
4use std::path::PathBuf;
5
6fn main() {
7 let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
8
9 // Generate memory.x - put "FLASH" at start of RAM, RAM after "FLASH"
10 // cortex-m-rt expects FLASH for code, RAM for data/bss/stack
11 // Both are in RAM, but separated to satisfy cortex-m-rt's expectations
12 // MCXA256 has 128KB RAM total
13 File::create(out.join("memory.x"))
14 .unwrap()
15 .write_all(include_bytes!("memory.x"))
16 .unwrap();
17
18 println!("cargo:rustc-link-search={}", out.display());
19 println!("cargo:rerun-if-changed=memory.x");
20}
diff --git a/examples/memory.x b/examples/memory.x
new file mode 100644
index 000000000..f4263a412
--- /dev/null
+++ b/examples/memory.x
@@ -0,0 +1,5 @@
1MEMORY
2{
3 FLASH : ORIGIN = 0x20000000, LENGTH = 64K
4 RAM : ORIGIN = 0x20010000, LENGTH = 64K
5}
diff --git a/examples/adc_interrupt.rs b/examples/src/bin/adc_interrupt.rs
index dc82cfd30..e174a5272 100644
--- a/examples/adc_interrupt.rs
+++ b/examples/src/bin/adc_interrupt.rs
@@ -2,17 +2,14 @@
2#![no_main] 2#![no_main]
3 3
4use embassy_executor::Spawner; 4use embassy_executor::Spawner;
5use embassy_mcxa_examples::{init_adc, init_uart2};
5use hal::adc::{LpadcConfig, TriggerPriorityPolicy}; 6use hal::adc::{LpadcConfig, TriggerPriorityPolicy};
6use hal::uart; 7use hal::pac::adc1::cfg::{Pwrsel, Refsel};
7use mcxa_pac::adc1::cfg::{Pwrsel, Refsel}; 8use hal::pac::adc1::cmdl1::{Adch, Mode};
8use mcxa_pac::adc1::cmdl1::{Adch, Mode}; 9use hal::pac::adc1::ctrl::CalAvgs;
9use mcxa_pac::adc1::ctrl::CalAvgs; 10use hal::pac::adc1::tctrl::Tcmd;
10use mcxa_pac::adc1::tctrl::Tcmd; 11use hal::{bind_interrupts, uart, InterruptExt};
11use {cortex_m, embassy_mcxa276 as hal}; 12use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _};
12mod common;
13
14use hal::{bind_interrupts, InterruptExt};
15use {defmt_rtt as _, panic_probe as _};
16 13
17bind_interrupts!(struct Irqs { 14bind_interrupts!(struct Irqs {
18 ADC1 => hal::adc::AdcHandler; 15 ADC1 => hal::adc::AdcHandler;
@@ -27,7 +24,7 @@ async fn main(_spawner: Spawner) {
27 let p = hal::init(hal::config::Config::default()); 24 let p = hal::init(hal::config::Config::default());
28 25
29 unsafe { 26 unsafe {
30 common::init_uart2(hal::pac()); 27 init_uart2(hal::pac());
31 } 28 }
32 29
33 let src = unsafe { hal::clocks::uart2_src_hz(hal::pac()) }; 30 let src = unsafe { hal::clocks::uart2_src_hz(hal::pac()) };
@@ -36,7 +33,7 @@ async fn main(_spawner: Spawner) {
36 uart.write_str_blocking("\r\n=== ADC interrupt Example ===\r\n"); 33 uart.write_str_blocking("\r\n=== ADC interrupt Example ===\r\n");
37 34
38 unsafe { 35 unsafe {
39 common::init_adc(hal::pac()); 36 init_adc(hal::pac());
40 } 37 }
41 38
42 let adc_config = LpadcConfig { 39 let adc_config = LpadcConfig {
diff --git a/examples/adc_polling.rs b/examples/src/bin/adc_polling.rs
index 4b5f9422d..741551d49 100644
--- a/examples/adc_polling.rs
+++ b/examples/src/bin/adc_polling.rs
@@ -1,21 +1,18 @@
1#![no_std] 1#![no_std]
2#![no_main] 2#![no_main]
3 3
4use core::fmt::Write;
5
4use embassy_executor::Spawner; 6use embassy_executor::Spawner;
5use embassy_mcxa276 as hal; 7use embassy_mcxa_examples::{init_adc, init_uart2};
6use hal::adc::{ConvResult, LpadcConfig, TriggerPriorityPolicy}; 8use hal::adc::{ConvResult, LpadcConfig, TriggerPriorityPolicy};
9use hal::pac::adc1::cfg::{Pwrsel, Refsel};
10use hal::pac::adc1::cmdl1::{Adch, Mode};
11use hal::pac::adc1::ctrl::CalAvgs;
12use hal::pac::adc1::tctrl::Tcmd;
7use hal::uart; 13use hal::uart;
8use mcxa_pac::adc1::cfg::{Pwrsel, Refsel};
9use mcxa_pac::adc1::cmdl1::{Adch, Mode};
10use mcxa_pac::adc1::ctrl::CalAvgs;
11use mcxa_pac::adc1::tctrl::Tcmd;
12
13mod common;
14
15use core::fmt::Write;
16
17use heapless::String; 14use heapless::String;
18use {defmt_rtt as _, panic_probe as _}; 15use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _};
19 16
20const G_LPADC_RESULT_SHIFT: u32 = 0; 17const G_LPADC_RESULT_SHIFT: u32 = 0;
21 18
@@ -24,7 +21,7 @@ async fn main(_spawner: Spawner) {
24 let p = hal::init(hal::config::Config::default()); 21 let p = hal::init(hal::config::Config::default());
25 22
26 unsafe { 23 unsafe {
27 common::init_uart2(hal::pac()); 24 init_uart2(hal::pac());
28 } 25 }
29 26
30 let src = unsafe { hal::clocks::uart2_src_hz(hal::pac()) }; 27 let src = unsafe { hal::clocks::uart2_src_hz(hal::pac()) };
@@ -33,7 +30,7 @@ async fn main(_spawner: Spawner) {
33 uart.write_str_blocking("\r\n=== ADC polling Example ===\r\n"); 30 uart.write_str_blocking("\r\n=== ADC polling Example ===\r\n");
34 31
35 unsafe { 32 unsafe {
36 common::init_adc(hal::pac()); 33 init_adc(hal::pac());
37 } 34 }
38 35
39 let adc_config = LpadcConfig { 36 let adc_config = LpadcConfig {
diff --git a/examples/blink.rs b/examples/src/bin/blink.rs
index 564353d5c..d8a57c546 100644
--- a/examples/blink.rs
+++ b/examples/src/bin/blink.rs
@@ -2,15 +2,13 @@
2#![no_main] 2#![no_main]
3 3
4use embassy_executor::Spawner; 4use embassy_executor::Spawner;
5use embassy_mcxa276 as hal; 5use embassy_mcxa as hal;
6use embassy_mcxa::bind_interrupts;
7use embassy_mcxa_examples::{init_led, init_ostimer0};
6use embassy_time::{Duration, Timer}; 8use embassy_time::{Duration, Timer};
7use hal::gpio::pins::PIO3_18; 9use hal::gpio::pins::PIO3_18;
8use hal::gpio::{Level, Output}; 10use hal::gpio::{Level, Output};
9 11
10mod common;
11
12use embassy_mcxa276::bind_interrupts;
13
14// Bind only OS_EVENT for timer interrupts 12// Bind only OS_EVENT for timer interrupts
15bind_interrupts!(struct Irqs { 13bind_interrupts!(struct Irqs {
16 OS_EVENT => hal::ostimer::time_driver::OsEventHandler; 14 OS_EVENT => hal::ostimer::time_driver::OsEventHandler;
@@ -24,13 +22,9 @@ static KEEP_OS_EVENT: unsafe extern "C" fn() = OS_EVENT;
24async fn main(_spawner: Spawner) { 22async fn main(_spawner: Spawner) {
25 let _p = hal::init(hal::config::Config::default()); 23 let _p = hal::init(hal::config::Config::default());
26 24
27 // Board-style init: enable LED GPIO/PORT clocks used by blink
28 unsafe {
29 common::init_led(hal::pac());
30 }
31 // Initialize OSTIMER for async timing
32 unsafe { 25 unsafe {
33 common::init_ostimer0(hal::pac()); 26 init_led(hal::pac());
27 init_ostimer0(hal::pac());
34 } 28 }
35 29
36 // Initialize embassy-time global driver backed by OSTIMER0 30 // Initialize embassy-time global driver backed by OSTIMER0
diff --git a/examples/hello.rs b/examples/src/bin/hello.rs
index e39adaced..5c4336d50 100644
--- a/examples/hello.rs
+++ b/examples/src/bin/hello.rs
@@ -2,12 +2,9 @@
2#![no_main] 2#![no_main]
3 3
4use embassy_executor::Spawner; 4use embassy_executor::Spawner;
5use embassy_mcxa276 as hal; 5use embassy_mcxa_examples::init_uart2;
6use hal::uart; 6use hal::uart;
7 7use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _};
8mod common;
9
10use {defmt_rtt as _, panic_probe as _};
11 8
12/// Simple helper to write a byte as hex to UART 9/// Simple helper to write a byte as hex to UART
13fn write_hex_byte(uart: &hal::uart::Uart<hal::uart::Lpuart2>, byte: u8) { 10fn write_hex_byte(uart: &hal::uart::Uart<hal::uart::Lpuart2>, byte: u8) {
@@ -24,7 +21,7 @@ async fn main(_spawner: Spawner) {
24 21
25 // Board-level init for UART2 clocks and pins. 22 // Board-level init for UART2 clocks and pins.
26 unsafe { 23 unsafe {
27 common::init_uart2(hal::pac()); 24 init_uart2(hal::pac());
28 } 25 }
29 26
30 // Get UART source frequency from clock configuration 27 // Get UART source frequency from clock configuration
@@ -74,7 +71,7 @@ async fn main(_spawner: Spawner) {
74 } else { 71 } else {
75 uart.write_str_blocking("Invalid number for hex command\r\n"); 72 uart.write_str_blocking("Invalid number for hex command\r\n");
76 } 73 }
77 } else if command.len() > 0 { 74 } else if !command.is_empty() {
78 uart.write_str_blocking("Unknown command: "); 75 uart.write_str_blocking("Unknown command: ");
79 uart.write_str_blocking(core::str::from_utf8(command).unwrap_or("")); 76 uart.write_str_blocking(core::str::from_utf8(command).unwrap_or(""));
80 uart.write_str_blocking("\r\n"); 77 uart.write_str_blocking("\r\n");
@@ -103,7 +100,7 @@ async fn main(_spawner: Spawner) {
103fn parse_u8(bytes: &[u8]) -> Result<u8, ()> { 100fn parse_u8(bytes: &[u8]) -> Result<u8, ()> {
104 let mut result = 0u8; 101 let mut result = 0u8;
105 for &b in bytes { 102 for &b in bytes {
106 if b >= b'0' && b <= b'9' { 103 if b.is_ascii_digit() {
107 result = result.checked_mul(10).ok_or(())?; 104 result = result.checked_mul(10).ok_or(())?;
108 result = result.checked_add(b - b'0').ok_or(())?; 105 result = result.checked_add(b - b'0').ok_or(())?;
109 } else { 106 } else {
diff --git a/examples/lpuart_buffered.rs b/examples/src/bin/lpuart_buffered.rs
index 35d311143..480d8e1f7 100644
--- a/examples/lpuart_buffered.rs
+++ b/examples/src/bin/lpuart_buffered.rs
@@ -2,14 +2,13 @@
2#![no_main] 2#![no_main]
3 3
4use embassy_executor::Spawner; 4use embassy_executor::Spawner;
5use embassy_mcxa276 as hal; 5use embassy_mcxa as hal;
6use embassy_mcxa276::interrupt::typelevel::Handler; 6use embassy_mcxa::interrupt::typelevel::Handler;
7use embassy_mcxa276::lpuart::buffered::BufferedLpuart; 7use embassy_mcxa::lpuart::buffered::BufferedLpuart;
8use embassy_mcxa276::{bind_interrupts, lpuart}; 8use embassy_mcxa::{bind_interrupts, lpuart};
9use embassy_mcxa_examples::{init_ostimer0, init_uart2};
9use embedded_io_async::{Read, Write}; 10use embedded_io_async::{Read, Write};
10 11
11mod common;
12
13// Bind OS_EVENT for timers plus LPUART2 IRQ for the buffered driver 12// Bind OS_EVENT for timers plus LPUART2 IRQ for the buffered driver
14bind_interrupts!(struct Irqs { 13bind_interrupts!(struct Irqs {
15 LPUART2 => lpuart::buffered::BufferedInterruptHandler::<lpuart::lib::peripherals::LPUART2>; 14 LPUART2 => lpuart::buffered::BufferedInterruptHandler::<lpuart::lib::peripherals::LPUART2>;
@@ -26,15 +25,15 @@ async fn main(_spawner: Spawner) {
26 let p2 = lpuart::lib::init(); 25 let p2 = lpuart::lib::init();
27 26
28 unsafe { 27 unsafe {
29 hal::interrupt::install_irq_handler(mcxa_pac::Interrupt::LPUART2, lpuart2_handler); 28 hal::interrupt::install_irq_handler(hal::pac::Interrupt::LPUART2, lpuart2_handler);
30 } 29 }
31 30
32 // Configure NVIC for LPUART2 31 // Configure NVIC for LPUART2
33 hal::interrupt::LPUART2.configure_for_uart(hal::interrupt::Priority::P3); 32 hal::interrupt::LPUART2.configure_for_uart(hal::interrupt::Priority::P3);
34 33
35 unsafe { 34 unsafe {
36 common::init_uart2(hal::pac()); 35 init_uart2(hal::pac());
37 common::init_ostimer0(hal::pac()); 36 init_ostimer0(hal::pac());
38 } 37 }
39 38
40 // UART configuration (enable both TX and RX) 39 // UART configuration (enable both TX and RX)
diff --git a/examples/lpuart_polling.rs b/examples/src/bin/lpuart_polling.rs
index 067c7eb53..215714569 100644
--- a/examples/lpuart_polling.rs
+++ b/examples/src/bin/lpuart_polling.rs
@@ -2,11 +2,9 @@
2#![no_main] 2#![no_main]
3 3
4use embassy_executor::Spawner; 4use embassy_executor::Spawner;
5use {defmt_rtt as _, embassy_mcxa276 as hal, panic_probe as _}; 5use embassy_mcxa_examples::init_uart2;
6 6use hal::lpuart::{lib, Config, Lpuart};
7use crate::hal::lpuart::{lib, Config, Lpuart}; 7use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _};
8
9mod common;
10 8
11#[embassy_executor::main] 9#[embassy_executor::main]
12async fn main(_spawner: Spawner) { 10async fn main(_spawner: Spawner) {
@@ -17,7 +15,7 @@ async fn main(_spawner: Spawner) {
17 15
18 // Board-level init for UART2 clocks and pins. 16 // Board-level init for UART2 clocks and pins.
19 unsafe { 17 unsafe {
20 common::init_uart2(hal::pac()); 18 init_uart2(hal::pac());
21 } 19 }
22 20
23 // Create UART configuration 21 // Create UART configuration
diff --git a/examples/ostimer_alarm.rs b/examples/src/bin/ostimer_alarm.rs
index 78ca4bbc5..953f98c01 100644
--- a/examples/ostimer_alarm.rs
+++ b/examples/src/bin/ostimer_alarm.rs
@@ -4,13 +4,10 @@
4use core::sync::atomic::{AtomicBool, Ordering}; 4use core::sync::atomic::{AtomicBool, Ordering};
5 5
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_mcxa::bind_interrupts;
8use embassy_mcxa_examples::{init_ostimer0, init_uart2};
7use hal::uart; 9use hal::uart;
8use {cortex_m, embassy_mcxa276 as hal}; 10use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _};
9
10mod common;
11
12use embassy_mcxa276::bind_interrupts;
13use {defmt_rtt as _, panic_probe as _};
14 11
15// Bind only OS_EVENT, and retain the symbol explicitly so it can't be GC'ed. 12// Bind only OS_EVENT, and retain the symbol explicitly so it can't be GC'ed.
16bind_interrupts!(struct Irqs { 13bind_interrupts!(struct Irqs {
@@ -35,10 +32,8 @@ async fn main(_spawner: Spawner) {
35 32
36 // Enable/clock OSTIMER0 and UART2 before touching their registers 33 // Enable/clock OSTIMER0 and UART2 before touching their registers
37 unsafe { 34 unsafe {
38 common::init_ostimer0(hal::pac()); 35 init_ostimer0(hal::pac());
39 } 36 init_uart2(hal::pac());
40 unsafe {
41 common::init_uart2(hal::pac());
42 } 37 }
43 let src = unsafe { hal::clocks::uart2_src_hz(hal::pac()) }; 38 let src = unsafe { hal::clocks::uart2_src_hz(hal::pac()) };
44 let uart = uart::Uart::<uart::Lpuart2>::new(p.LPUART2, uart::Config::new(src)); 39 let uart = uart::Uart::<uart::Lpuart2>::new(p.LPUART2, uart::Config::new(src));
diff --git a/examples/ostimer_async.rs b/examples/src/bin/ostimer_async.rs
index 27e14e022..34862b61f 100644
--- a/examples/ostimer_async.rs
+++ b/examples/src/bin/ostimer_async.rs
@@ -2,14 +2,11 @@
2#![no_main] 2#![no_main]
3 3
4use embassy_executor::Spawner; 4use embassy_executor::Spawner;
5use embassy_mcxa276 as hal; 5use embassy_mcxa::bind_interrupts;
6use hal::uart; 6use embassy_mcxa_examples::{init_ostimer0, init_uart2};
7
8mod common;
9
10use embassy_mcxa276::bind_interrupts;
11use embassy_time::{Duration, Timer}; 7use embassy_time::{Duration, Timer};
12use {defmt_rtt as _, panic_probe as _}; 8use hal::uart;
9use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _};
13 10
14// Bind only OS_EVENT, and retain the symbol explicitly so it can’t be GC’ed. 11// Bind only OS_EVENT, and retain the symbol explicitly so it can’t be GC’ed.
15bind_interrupts!(struct Irqs { 12bind_interrupts!(struct Irqs {
@@ -26,10 +23,8 @@ async fn main(_spawner: Spawner) {
26 23
27 // Enable/clock OSTIMER0 and UART2 before touching their registers 24 // Enable/clock OSTIMER0 and UART2 before touching their registers
28 unsafe { 25 unsafe {
29 common::init_ostimer0(hal::pac()); 26 init_ostimer0(hal::pac());
30 } 27 init_uart2(hal::pac());
31 unsafe {
32 common::init_uart2(hal::pac());
33 } 28 }
34 let src = unsafe { hal::clocks::uart2_src_hz(hal::pac()) }; 29 let src = unsafe { hal::clocks::uart2_src_hz(hal::pac()) };
35 let uart = uart::Uart::<uart::Lpuart2>::new(_p.LPUART2, uart::Config::new(src)); 30 let uart = uart::Uart::<uart::Lpuart2>::new(_p.LPUART2, uart::Config::new(src));
diff --git a/examples/ostimer_counter.rs b/examples/src/bin/ostimer_counter.rs
index e95140a88..20044760a 100644
--- a/examples/ostimer_counter.rs
+++ b/examples/src/bin/ostimer_counter.rs
@@ -7,11 +7,10 @@
7#![no_main] 7#![no_main]
8 8
9use embassy_executor::Spawner; 9use embassy_executor::Spawner;
10use embassy_mcxa_examples::{init_ostimer0, init_uart2};
10use embassy_time::{Duration, Timer}; 11use embassy_time::{Duration, Timer};
11use hal::bind_interrupts; 12use hal::bind_interrupts;
12use {defmt_rtt as _, embassy_mcxa276 as hal, panic_probe as _}; 13use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _};
13
14mod common;
15 14
16bind_interrupts!(struct Irqs { 15bind_interrupts!(struct Irqs {
17 OS_EVENT => hal::ostimer::time_driver::OsEventHandler; 16 OS_EVENT => hal::ostimer::time_driver::OsEventHandler;
@@ -23,10 +22,8 @@ async fn main(_spawner: Spawner) {
23 22
24 // Enable/clock OSTIMER0 and UART2 before touching their registers 23 // Enable/clock OSTIMER0 and UART2 before touching their registers
25 unsafe { 24 unsafe {
26 common::init_ostimer0(hal::pac()); 25 init_ostimer0(hal::pac());
27 } 26 init_uart2(hal::pac());
28 unsafe {
29 common::init_uart2(hal::pac());
30 } 27 }
31 let src = unsafe { hal::clocks::uart2_src_hz(hal::pac()) }; 28 let src = unsafe { hal::clocks::uart2_src_hz(hal::pac()) };
32 let mut uart = hal::uart::Uart::<hal::uart::Lpuart2>::new(p.LPUART2, hal::uart::Config::new(src)); 29 let mut uart = hal::uart::Uart::<hal::uart::Lpuart2>::new(p.LPUART2, hal::uart::Config::new(src));
diff --git a/examples/ostimer_race_test.rs b/examples/src/bin/ostimer_race_test.rs
index 368a3e52f..720a058d5 100644
--- a/examples/ostimer_race_test.rs
+++ b/examples/src/bin/ostimer_race_test.rs
@@ -12,11 +12,10 @@
12use core::sync::atomic::{AtomicU32, Ordering}; 12use core::sync::atomic::{AtomicU32, Ordering};
13 13
14use embassy_executor::Spawner; 14use embassy_executor::Spawner;
15use embassy_mcxa_examples::{init_ostimer0, init_uart2};
15use embassy_time::{Duration, Timer}; 16use embassy_time::{Duration, Timer};
16use hal::bind_interrupts; 17use hal::bind_interrupts;
17use {defmt_rtt as _, embassy_mcxa276 as hal, panic_probe as _}; 18use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _};
18
19mod common;
20 19
21bind_interrupts!(struct Irqs { 20bind_interrupts!(struct Irqs {
22 OS_EVENT => hal::ostimer::time_driver::OsEventHandler; 21 OS_EVENT => hal::ostimer::time_driver::OsEventHandler;
@@ -73,10 +72,8 @@ async fn main(_spawner: Spawner) {
73 72
74 // Enable/clock OSTIMER0 and UART2 before touching their registers 73 // Enable/clock OSTIMER0 and UART2 before touching their registers
75 unsafe { 74 unsafe {
76 common::init_ostimer0(hal::pac()); 75 init_ostimer0(hal::pac());
77 } 76 init_uart2(hal::pac());
78 unsafe {
79 common::init_uart2(hal::pac());
80 } 77 }
81 let src = unsafe { hal::clocks::uart2_src_hz(hal::pac()) }; 78 let src = unsafe { hal::clocks::uart2_src_hz(hal::pac()) };
82 let mut uart = hal::uart::Uart::<hal::uart::Lpuart2>::new(p.LPUART2, hal::uart::Config::new(src)); 79 let mut uart = hal::uart::Uart::<hal::uart::Lpuart2>::new(p.LPUART2, hal::uart::Config::new(src));
@@ -267,7 +264,7 @@ async fn test_concurrent_operations(
267async fn test_reset_during_operation( 264async fn test_reset_during_operation(
268 ostimer: &hal::ostimer::Ostimer<'_, hal::ostimer::Ostimer0>, 265 ostimer: &hal::ostimer::Ostimer<'_, hal::ostimer::Ostimer0>,
269 uart: &mut hal::uart::Uart<hal::uart::Lpuart2>, 266 uart: &mut hal::uart::Uart<hal::uart::Lpuart2>,
270 peripherals: &mcxa_pac::Peripherals, 267 peripherals: &hal::pac::Peripherals,
271) { 268) {
272 let initial_counter = ostimer.now(); 269 let initial_counter = ostimer.now();
273 270
diff --git a/examples/rtc_alarm.rs b/examples/src/bin/rtc_alarm.rs
index c27fd4c55..dc07b5757 100644
--- a/examples/rtc_alarm.rs
+++ b/examples/src/bin/rtc_alarm.rs
@@ -2,15 +2,14 @@
2#![no_main] 2#![no_main]
3 3
4use embassy_executor::Spawner; 4use embassy_executor::Spawner;
5use embassy_mcxa as hal;
6use embassy_mcxa_examples::init_uart2;
5use hal::rtc::{RtcDateTime, RtcInterruptEnable}; 7use hal::rtc::{RtcDateTime, RtcInterruptEnable};
6use hal::{uart, InterruptExt}; 8use hal::{uart, InterruptExt};
7use {cortex_m, embassy_mcxa276 as hal};
8
9mod common;
10 9
11type MyRtc = hal::rtc::Rtc<hal::rtc::Rtc0>; 10type MyRtc = hal::rtc::Rtc<hal::rtc::Rtc0>;
12 11
13use embassy_mcxa276::bind_interrupts; 12use embassy_mcxa::bind_interrupts;
14use {defmt_rtt as _, panic_probe as _}; 13use {defmt_rtt as _, panic_probe as _};
15 14
16bind_interrupts!(struct Irqs { 15bind_interrupts!(struct Irqs {
@@ -26,7 +25,7 @@ async fn main(_spawner: Spawner) {
26 let p = hal::init(hal::config::Config::default()); 25 let p = hal::init(hal::config::Config::default());
27 26
28 unsafe { 27 unsafe {
29 common::init_uart2(hal::pac()); 28 init_uart2(hal::pac());
30 } 29 }
31 30
32 let src = unsafe { hal::clocks::uart2_src_hz(hal::pac()) }; 31 let src = unsafe { hal::clocks::uart2_src_hz(hal::pac()) };
@@ -82,6 +81,4 @@ async fn main(_spawner: Spawner) {
82 } 81 }
83 82
84 uart.write_str_blocking("Example complete - Test PASSED!\r\n"); 83 uart.write_str_blocking("Example complete - Test PASSED!\r\n");
85
86 loop {}
87} 84}
diff --git a/examples/uart_interrupt.rs b/examples/src/bin/uart_interrupt.rs
index bd734f859..100588727 100644
--- a/examples/uart_interrupt.rs
+++ b/examples/src/bin/uart_interrupt.rs
@@ -2,14 +2,11 @@
2#![no_main] 2#![no_main]
3 3
4use embassy_executor::Spawner; 4use embassy_executor::Spawner;
5use embassy_mcxa276 as hal; 5use embassy_mcxa::bind_interrupts;
6use embassy_mcxa_examples::init_uart2;
6use hal::interrupt::typelevel::Handler; 7use hal::interrupt::typelevel::Handler;
7use hal::uart; 8use hal::uart;
8 9use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _};
9mod common;
10
11use embassy_mcxa276::bind_interrupts;
12use {defmt_rtt as _, panic_probe as _};
13 10
14// Bind LPUART2 interrupt to our handler 11// Bind LPUART2 interrupt to our handler
15bind_interrupts!(struct Irqs { 12bind_interrupts!(struct Irqs {
@@ -31,7 +28,7 @@ async fn main(_spawner: Spawner) {
31 28
32 // Enable/clock UART2 before touching its registers 29 // Enable/clock UART2 before touching its registers
33 unsafe { 30 unsafe {
34 common::init_uart2(hal::pac()); 31 init_uart2(hal::pac());
35 } 32 }
36 let src = unsafe { hal::clocks::uart2_src_hz(hal::pac()) }; 33 let src = unsafe { hal::clocks::uart2_src_hz(hal::pac()) };
37 let uart = uart::Uart::<uart::Lpuart2>::new(_p.LPUART2, uart::Config::new(src)); 34 let uart = uart::Uart::<uart::Lpuart2>::new(_p.LPUART2, uart::Config::new(src));
diff --git a/examples/common/mod.rs b/examples/src/common/mod.rs
index 8c52c8e86..8cb4590f8 100644
--- a/examples/common/mod.rs
+++ b/examples/src/common/mod.rs
@@ -2,12 +2,12 @@
2//! These live with the examples so the HAL stays generic. 2//! These live with the examples so the HAL stays generic.
3 3
4use hal::{clocks, pins, reset}; 4use hal::{clocks, pins, reset};
5use {embassy_mcxa276 as hal, panic_probe as _}; 5use {embassy_mcxa as hal, panic_probe as _};
6 6
7/// Initialize clocks and pin muxing for UART2 debug console. 7/// Initialize clocks and pin muxing for UART2 debug console.
8/// Safe to call multiple times; writes are idempotent for our use. 8/// Safe to call multiple times; writes are idempotent for our use.
9#[allow(dead_code)] 9#[allow(dead_code)]
10pub unsafe fn init_uart2(p: &mcxa_pac::Peripherals) { 10pub unsafe fn init_uart2(p: &hal::pac::Peripherals) {
11 clocks::ensure_frolf_running(p); 11 clocks::ensure_frolf_running(p);
12 clocks::enable_uart2_port2(p); 12 clocks::enable_uart2_port2(p);
13 reset::release_reset_port2(p); 13 reset::release_reset_port2(p);
@@ -18,7 +18,7 @@ pub unsafe fn init_uart2(p: &mcxa_pac::Peripherals) {
18 18
19/// Initialize clocks for the LED GPIO/PORT used by the blink example. 19/// Initialize clocks for the LED GPIO/PORT used by the blink example.
20#[allow(dead_code)] 20#[allow(dead_code)]
21pub unsafe fn init_led(p: &mcxa_pac::Peripherals) { 21pub unsafe fn init_led(p: &hal::pac::Peripherals) {
22 clocks::enable_led_port(p); 22 clocks::enable_led_port(p);
23 reset::release_reset_gpio3(p); 23 reset::release_reset_gpio3(p);
24 reset::release_reset_port3(p); 24 reset::release_reset_port3(p);
@@ -26,7 +26,7 @@ pub unsafe fn init_led(p: &mcxa_pac::Peripherals) {
26 26
27/// Initialize clocks for OSTIMER0 (1 MHz source). 27/// Initialize clocks for OSTIMER0 (1 MHz source).
28#[allow(dead_code)] 28#[allow(dead_code)]
29pub unsafe fn init_ostimer0(p: &mcxa_pac::Peripherals) { 29pub unsafe fn init_ostimer0(p: &hal::pac::Peripherals) {
30 clocks::ensure_frolf_running(p); 30 clocks::ensure_frolf_running(p);
31 clocks::enable_ostimer0(p); 31 clocks::enable_ostimer0(p);
32 reset::release_reset_ostimer0(p); 32 reset::release_reset_ostimer0(p);
@@ -35,7 +35,7 @@ pub unsafe fn init_ostimer0(p: &mcxa_pac::Peripherals) {
35 35
36/// Initialize clocks and pin muxing for ADC. 36/// Initialize clocks and pin muxing for ADC.
37#[allow(dead_code)] 37#[allow(dead_code)]
38pub unsafe fn init_adc(p: &mcxa_pac::Peripherals) { 38pub unsafe fn init_adc(p: &hal::pac::Peripherals) {
39 clocks::ensure_frolf_running(p); 39 clocks::ensure_frolf_running(p);
40 clocks::enable_adc(p); 40 clocks::enable_adc(p);
41 reset::release_reset_port1(p); 41 reset::release_reset_port1(p);
diff --git a/examples/src/lib.rs b/examples/src/lib.rs
new file mode 100644
index 000000000..cf4194559
--- /dev/null
+++ b/examples/src/lib.rs
@@ -0,0 +1,63 @@
1#![no_std]
2
3//! Shared board-specific helpers for the FRDM-MCXA276 examples.
4//! These live with the examples so the HAL stays generic.
5
6use hal::{clocks, pins, reset};
7use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _};
8
9/// Initialize clocks and pin muxing for UART2 debug console.
10/// Safe to call multiple times; writes are idempotent for our use.
11///
12/// # Safety
13///
14/// Called only once to initialize the peripheral
15#[allow(dead_code)]
16pub unsafe fn init_uart2(p: &hal::pac::Peripherals) {
17 clocks::ensure_frolf_running(p);
18 clocks::enable_uart2_port2(p);
19 reset::release_reset_port2(p);
20 reset::release_reset_lpuart2(p);
21 pins::configure_uart2_pins_port2();
22 clocks::select_uart2_clock(p);
23}
24
25/// Initialize clocks for the LED GPIO/PORT used by the blink example.
26///
27/// # Safety
28///
29/// Called only once to initialize the peripheral
30#[allow(dead_code)]
31pub unsafe fn init_led(p: &hal::pac::Peripherals) {
32 clocks::enable_led_port(p);
33 reset::release_reset_gpio3(p);
34 reset::release_reset_port3(p);
35}
36
37/// Initialize clocks for OSTIMER0 (1 MHz source).
38///
39/// # Safety
40///
41/// Called only once to initialize the peripheral
42#[allow(dead_code)]
43pub unsafe fn init_ostimer0(p: &hal::pac::Peripherals) {
44 clocks::ensure_frolf_running(p);
45 clocks::enable_ostimer0(p);
46 reset::release_reset_ostimer0(p);
47 clocks::select_ostimer0_clock_1m(p);
48}
49
50/// Initialize clocks and pin muxing for ADC.
51///
52/// # Safety
53///
54/// Called only once to initialize the peripheral
55#[allow(dead_code)]
56pub unsafe fn init_adc(p: &hal::pac::Peripherals) {
57 clocks::ensure_frolf_running(p);
58 clocks::enable_adc(p);
59 reset::release_reset_port1(p);
60 reset::release_reset_adc1(p);
61 pins::configure_adc_pins();
62 clocks::select_adc_clock(p);
63}