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

Default compiler flags for debug mode make the example program not fit in flash on CH32V203 #14

Closed
kleinesfilmroellchen opened this issue Jan 2, 2025 · 1 comment · May be fixed by #15
Assignees

Comments

@kleinesfilmroellchen
Copy link

Using rustc 1.85.0-nightly (45d11e51b 2025-01-01) I generated a project with this template for CH32V203 with the G8R6 pinout. Unfortunately, since no compiler flags overrides are defined for debug mode, this leads to the data sections being too large for the flash:

  = note: rust-lld: error: section '.rodata' will not fit in region 'FLASH': overflowed by 3664 bytes
          rust-lld: error: section '.rodata' will not fit in region 'FLASH': overflowed by 3664 bytes
          rust-lld: error: section '.data' will not fit in region 'FLASH': overflowed by 3712 bytes
          rust-lld: error: section '.bss' will not fit in region 'FLASH': overflowed by 4240 bytes

Simply adding

[profile.dev]
opt-level = 's'

to Cargo.toml fixes this, without affecting compile times much. It would be nice if this was added to the template, since developers expect to be able to compile even embedded programs in debug mode for a faster development cycle, at least as long as they haven’t added too much code. Otherwise, I would add a warning about not using release mode to Cargo.toml or the README.

On that note, opt-level = 'z' (strong size optimization) should be considered for release mode. For the example program, without too much extra compile time it halves the code size from 10K to 5K, and decreases the read-only data size from 5K to just under 300 bytes.

@andelf andelf self-assigned this Jan 2, 2025
romainreignier added a commit that referenced this issue Jan 2, 2025
@romainreignier
Copy link
Contributor

Thanks, fixed with #15

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 a pull request may close this issue.

3 participants