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

Wrong flash sizes on 8KB flash AVR parts #207

Closed
ospilos opened this issue Jul 25, 2020 · 12 comments
Closed

Wrong flash sizes on 8KB flash AVR parts #207

ospilos opened this issue Jul 25, 2020 · 12 comments

Comments

@ospilos
Copy link

ospilos commented Jul 25, 2020

There is an issue of incorretly staded flash size on bare AVR parts with 8KB of flash memory, namely:
https://github.com/platformio/platform-atmelavr/blob/develop/boards/ATmega8.json
https://github.com/platformio/platform-atmelavr/blob/develop/boards/ATmega88.json
https://github.com/platformio/platform-atmelavr/blob/develop/boards/ATmega88P.json
https://github.com/platformio/platform-atmelavr/blob/develop/boards/ATmega88PB.json

The value of "upload" -> "maximum_size": is 7680, while it should probably be 8192 as these are bare ICS, therefore without any bootloader in them.

On the other side
https://github.com/platformio/platform-atmelavr/blob/develop/boards/ATmega48.json
seems to advertise the whole flash size in the json definitions.

In fact this is incosistent across most of the bare IC definitions, as ATMEGA parts mostly has the flash size liited, while ATTINY parts seem to advertise the whole flash size.

@MCUdude
Copy link
Contributor

MCUdude commented Jul 28, 2020

By default, the PlatformIO/MiniCore implementation includes a 512-byte bootloader by default. If you don't want to use a bootloader you can just redefine the flash size in platformio.ini.

build_upload.maximum_size = 8192

The ATmega48 doesn't have a bootloader section. Thats why all 4096 bytes are "available" by default.

@MCUdude
Copy link
Contributor

MCUdude commented Nov 17, 2020

@valeros would it be possible to automatically add 512 bytes to the build_upload.maximum_size somewhere if a bootloader is in use? I looked through the main.py file in this repo, but I couldn't find any references to this.

@valeros
Copy link
Member

valeros commented Nov 19, 2020

I agree that all these manifests rather represent bare MCUs than full-fledged boards. IMO, the manifests should contain the precise memory size without any assumptions on bootloader presence. Anyone who want to use bootloader then should use the build_upload.maximum_size option.

@MCUdude
Copy link
Contributor

MCUdude commented Nov 20, 2020

Anyone who wants to use bootloader then should use the build_upload.maximum_size option.

@valeros is this something that could be handled automatically for bare MCUs that are supported by Mighty/Mega/Mini/Major/MicroCore? We know the bootloader sizes for the various targets (512B or 1024B). Mabe a field in the manifest file: build_upload.bootloader_size = 512?

@valeros
Copy link
Member

valeros commented Nov 24, 2020

TBH, I'm a bit reluctant to pollute manifests with core-specific configurations. I guess users who know how to use bootloader should be aware of memory constraints it brings. Besides, how can we determine whether a target is using bootloader to reduce the memory size accordingly?

@MCUdude
Copy link
Contributor

MCUdude commented Nov 24, 2020

For those who aren't using a bootloader, they are probably using the manifest files meant to be used with "my" Arduino cores. Since I've compiled all the bootloaders for all these boards, I know how big they are and how much space is allocated in every microcontroller.

Just for fun, the bootloader build scrip I'm using also generates a file that contains some information about every file, for example atmega1284p_build_info.txt. But what matters here is the actual allocated space set by the fuse bits.

Here's the rule for MightyCore, MegaCore, MiniCore and MajorCore:

  • 1024 bytes are allocated if the microcontroller flash memory is greater or equal to 64kB
  • 512 bytes are allocated if the microcontroller flash memory is less or equal to 32 kB.
  • Exceptions:
    • ATmega48/P/PB does not have a bootloader section and can therefore not have a "regular" bootloader. Hence, 4096 bytes are available. This is true for all "classic"AVRs with 4kB or less.
    • AT90CAN32 has 32kB of flash, but 1024 bytes are allocated for the bootloader. This is because the compiled bootloader size is more than 512 bytes, and the next step is to allocate 1024 bytes

@valeros
Copy link
Member

valeros commented Nov 24, 2020

Thanks for the info, but the question still remains, how can we detect that a bootloader is used and accordingly subtract the default bootloader size from the maximum_size field.

@MCUdude
Copy link
Contributor

MCUdude commented Nov 24, 2020

Thanks for the info, but the question still remains, how can we detect that a bootloader is used and accordingly subtract the default bootloader size from the maximum_size field.

My cores support board_hardware.uart. Subtract 512 or 1024 bytes if board_hardware.uart is not no_bootloader. board_hardware.uart = uart0 is the default value for all these chips anyways at the moment. The user has to explicitly write in the platformio.ini file that no bootloader should be used: board_hardware.uart = no_bootloader.

@valeros
Copy link
Member

valeros commented Nov 24, 2020

@MCUdude Could you please update the maximum_size field in your manifests so it will represent the whole flash size. Then I will be able to subtract the bootloader size if no_bootloader isn't set. Thanks!

@MCUdude
Copy link
Contributor

MCUdude commented Nov 24, 2020

MCUdude Could you please update the maximum_size field in your manifests so it will represent the whole flash size. Then I will be able to subtract the bootloader size if no_bootloader isn't set. Thanks!

Sure! I'll see if I can submit a PR tonight.

@valeros
Copy link
Member

valeros commented Nov 27, 2020

@MCUdude Could you please take a look at 216f574. Did I miss anything in the calculation process?

@MCUdude
Copy link
Contributor

MCUdude commented Nov 27, 2020

@valeros looks good to me!

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

No branches or pull requests

3 participants