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

STM32 I2C size improvements, STM32G030 support #1540

Merged
merged 7 commits into from
Sep 19, 2023
Merged

Conversation

cbiffle
Copy link
Collaborator

@cbiffle cbiffle commented Sep 17, 2023

On the 0xCon demo board, I included a "standard" Sparkfun/Adafruit I2C connector. I later realized that we don't actually have I2C support working on the G030 for space reasons. (Last night, while I was attempting to sleep.) So this morning I've thoroughly beaten the i2c server with the "get smaller" stick, and have it fitting in under 4 kiB. (For comparison, on donglet, the next larger target, it takes 16 kiB.)

This has required turning panic messages off (code contains a lot of panics) and disabling ringbuf (code contains a lot of ringbuf). Among other things.

There appear to be more opportunities for flash reclamation in these crates -- as far as I can tell nobody's been keeping an eye on overflow panics or bounds check panics, which are generating a lot of goo. So, I may have follow-ups. TBD.

FixedMap contains a runtime capacity check that has, as far as I can
tell, never fired. This means it doesn't need an explanatory error
message -- file/line should be sufficient.

Removing the message saves a good chunk of text.
The hl::recv facility is _almost_ dead, but the single user I can find
(the I2C server) is quite popular, so we have to maintain it. Sigh.

It's entirely possible for rm.message_len to be larger than the buffer:
if the client sends an overly long message, the kernel will report that.
So, this code has been a client-controlled server panic for ages.

This switches it to check the message length when slicing, and transfer
the panic to the client, where it belongs.

This happens to remove a hundred bytes or so of text, by removing the
setup and call to the slice index bounds fail routine.
Previously, sleep_for was using normal arithmetic to compute a deadline
from the given number of ticks. We don't expect ticks to overflow in
practice (it's 64-bit) but normal arithmetic checks for overflow. This
means sleeping with a very very large interval would produce a panic.

A panic from arithmetic overflow is somewhat more expensive than a
no-message explicit panic, or an unwrap_lite. This commit changes the
arithmetic to do checks explicitly and unwrap_lite on failure, saving a
chunk of text.
task_slot checks its own build system behavior at runtime at a
nontrivial cost, particularly in tasks with few panics. I'd argue this
is unnecessary because

1. This has, as far as I can tell, never failed.
2. Should it fail, the kernel will fault us with a "task index out of
   range" fault, so it's not like it'll be silently ignored.

Fixes #1538.
I'm pretty sure the "laps" counter variable couldn't overflow, but this
was not obvious to the compiler, which was generating checks and panics.

Restructuring the loop to use explicit iteration bounds fixes this.

This knocks about 100 bytes off the I2C server.
I'm pretty sure the wiggles variable (a u8) could not overflow here, but
the compiler is less convinced and was generating checks.

Switched it to explicitly wrapping arithmetic for some text savings.
@cbiffle cbiffle force-pushed the oxcon2023g0-i2c branch 2 times, most recently from 0e1437e to ff8f4aa Compare September 17, 2023 19:23
scl.pin = 11
sda.pin = 10
af = 6

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: bonus whitespace here

This is the shotgun change required to teach all the various bits that
g030 exists, plus adding it to the oxcon2023g0 demo app.

The main functional change here: panic messages can now be disabled in
the i2c server for specific targets. It'd be nice to have explicit
control over this, instead of having it depend on the target, but the
way things are currently structured that's not practical.

With panic messages off we can fit the server in less than 4 kiB, making
it practical on STM32G030.
@cbiffle cbiffle enabled auto-merge (rebase) September 19, 2023 16:14
@cbiffle cbiffle merged commit e6cf181 into master Sep 19, 2023
71 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants