Skip to content

esp8266: Add per-board configs, following other ports. #5118

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

Closed
wants to merge 10 commits into from

Conversation

mcauser
Copy link
Contributor

@mcauser mcauser commented Sep 18, 2019

Defaults to BOARD=GENERIC.

  • Added /boards
  • Added /boards/GENERIC
  • Added /boards/GENERIC_512K
  • Moved ld files to /boards
  • Remove 512k from Makefile
  • Remove mpconfigport_512k.h - it's now in /boards/GENERIC_512K
  • Update the README.md - 512KB FlashROM version
  • Add other boards to test in .travis.yml

For later:

@mcauser
Copy link
Contributor Author

mcauser commented Sep 18, 2019

Inspired by #4991

ifeq ($(wildcard $(BOARD_DIR)/.),)
$(error Invalid BOARD specified: $(BOARD_DIR))
endif

include ../../py/mkenv.mk

# qstr definitions (must come before including py.mk)
Copy link
Member

Choose a reason for hiding this comment

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

To match other ports, can you also add:

-include $(BOARD_DIR)/mpconfigboard.mk

Note the - on the front to make it optional.

Although it won't be used for the generic board, it's possible another board might want it (e.g. to reference additional code outside the board dir (e.g. extmod) or to change compiler/linker flags).

@mcauser
Copy link
Contributor Author

mcauser commented Sep 18, 2019

Failing when trying to load build/main.o in /ports/esp8266/esp8266_common.ld
Should be build-GENERIC/main.o

@mcauser
Copy link
Contributor Author

mcauser commented Sep 18, 2019

So, what are the most popular boards?

  • Adafruit Feather HUZZAH
  • Adafruit HUZZAH
  • NodeMCU DevKit
  • SparkFun Thing
  • Wemos D1 Mini
  • Wemos D1 Mini Lite
  • Wemos D1 Mini Pro
  • WiFi Witty
  • Wio Link

@nevercast
Copy link
Contributor

nevercast commented Sep 26, 2019

So, what are the most popular boards

I think we can add those as seperate PRs, right?

@jimmo Are you happy with this PR? Can you say it is reviewed?

@dpgeorge
Copy link
Member

Looks good to me.

I agree other boards can be added later. First thing to do would be convert the 512k build to a board.

@mcauser
Copy link
Contributor Author

mcauser commented Sep 30, 2019

Had a crack at adding the 512K board. A few things I'm not sure about

a) Can board names start with a number? /boards/512K

b) Not sure about these 3x in mpconfigport_512k.h:

#undef mp_import_stat
#undef mp_builtin_open
#undef mp_builtin_open_obj

It used to run after #include <mpconfigport.h> but now /boards/512K/mpconfigboard.h runs before. Add a custom #define in the *board.h and perform the #undef's in the *port.h if defined?

c) Should esp8266_512k.ld be moved into the /ports/esp8266/boards/512K dir? Like the nrf particle_xenon does in #5158

d) Should every #define in /ports/esp8266/mpconfigport.h be wrapped in a #ifndef so boards can define them (first)? Or only add when first needed?

@dpgeorge
Copy link
Member

Can board names start with a number?

Good question! Probably best not to. In this case it could be GENERIC_512K

b) Not sure about these 3x in mpconfigport_512k.h...

Are they needed at all? What happens with these just removed?

Should esp8266_512k.ld be moved

Maybe moved to ports/esp8266/boards/ dir, so it can be reused by other 512k boards if needed.

Should every #define in /ports/esp8266/mpconfigport.h be wrapped in a #ifndef so boards can define them (first)? Or only add when first needed?

Only add when first needed.

@dpgeorge
Copy link
Member

dpgeorge commented Oct 4, 2019

@mcauser is this ready to review, or do you plan to tick all the boxes in the first post?

@mcauser
Copy link
Contributor Author

mcauser commented Oct 4, 2019

@dpgeorge I’ll cleanup the 512k bits first then push the other tasks to separate PRs

@mcauser
Copy link
Contributor Author

mcauser commented Oct 4, 2019

Hi @dpgeorge , Over to you for review.

@mcauser
Copy link
Contributor Author

mcauser commented Oct 4, 2019

$ tools/check_code_size.sh
Old size: 68848 new size: 68852
Validation failure: Core code size increased
The command "tools/check_code_size.sh" exited with 1.

Not sure what increased the minimal build by 4 (bytes?).

@nevercast
Copy link
Contributor

Not sure what increased the minimal build by 4 (bytes?).

Did the board or MCU name change ?

@mcauser
Copy link
Contributor Author

mcauser commented Oct 5, 2019

@nevercast on the 512K board it did.

#define MICROPY_HW_BOARD_NAME "ESP module"
#define MICROPY_HW_BOARD_NAME "ESP module (512K)"

Not sure how that impacts the minimal build though

@mcauser
Copy link
Contributor Author

mcauser commented Oct 7, 2019

Rebased off master, CI now passes 👌

Copy link
Member

@dpgeorge dpgeorge left a comment

Choose a reason for hiding this comment

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

Great work! Just a few comments inline.

#define MICROPY_PERSISTENT_CODE_LOAD (1)
#endif
Copy link
Member

Choose a reason for hiding this comment

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

I think with all these options that have guards added in this file, it'd be much simple to just not configure them at all here. Instead, the mpconfigboard.h file should enable the features it wants. So in GENERIC_512K/mpconfigboard.h it'd be pretty much empty. And in GENERIC/mpconfigboard.h it'd enable all the extra features.

Then this file here would be almost unchanged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would bring it closer in line with the STM32 port, where features are off by default and enabled in board specific mpconfigboard.h's

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated as per your recommendations.
Defaults in /py/mpconfig.h, with common features enabled in /ports/esp8266/mpconfigboard.h, and board specific features enabled in /ports/esp8266/boards/GENERIC/mpconfigboard.h.

Copy link
Member

Choose a reason for hiding this comment

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

Looks good!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the STM32 port, there's an additional mpconfigboard_common.h, which sets defaults for boards which do not provide enough config.

Copy link
Member

Choose a reason for hiding this comment

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

That extra complexity isn't needed here, at least not now.

@dpgeorge
Copy link
Member

Not sure why the 512k build fails...

@dpgeorge
Copy link
Member

Not sure why the 512k build fails...

Looks like it has to do with the changes I suggested to esp8266_common.ld, removing build-*.

Can you please revert that, ie use build-*/main.o ... etc?

@mcauser
Copy link
Contributor Author

mcauser commented Oct 10, 2019

xtensa-lx106-elf-ld: build-GENERIC_512K/firmware.elf section `.irom0.text' will not fit in region `irom0_0_seg'
xtensa-lx106-elf-ld: region `irom0_0_seg' overflowed by 1544 bytes
make: *** [build-GENERIC_512K/firmware.elf] Error 1

Undo, Abort, Retry

Instead of disabling features in boards/GENERIC_512K
@mcauser
Copy link
Contributor Author

mcauser commented Oct 10, 2019

Rolled back changes to esp8266_common.ld. Builds locally now.

LINK build-GENERIC_512K/firmware.elf
   text	   data	    bss	    dec	    hex	filename
 498124	   1024	  65960	 565108	  89f74	build-GENERIC_512K/firmware.elf
Create build-GENERIC_512K/firmware-combined.bin
esptool.py v1.2
flash     33088
padding   3776
irom0text 466104
total     502968
md5       06617a4ca7a2046cbf55ddb860564949

@mcauser
Copy link
Contributor Author

mcauser commented Oct 10, 2019

GENERIC also builds successfully on my local.

LINK build-GENERIC/firmware.elf
   text	   data	    bss	    dec	    hex	filename
 586988	   1040	  66520	 654548	  9fcd4	build-GENERIC/firmware.elf
Create build-GENERIC/firmware-combined.bin
esptool.py v1.2
flash     33104
padding   3760
irom0text 554968
total     591832
md5       e75afe51f0f8e91323cc8df065baaf33

@mcauser
Copy link
Contributor Author

mcauser commented Oct 10, 2019

Found an old ESP-01 with 512K flash (25Q40BT). Deployed GENERIC_512K to it. Works!

MicroPython v1.11-422-g2941879e0-dirty on 2019-10-10; ESP module (512K) with ESP8266
Type "help()" for more information.
>>> import micropython
>>> micropython.mem_info()
stack: 2112 out of 8192
GC: total: 37952, used: 688, free: 37264
 No. of 1-blocks: 14, 2-blocks: 7, max blk sz: 5, max free sz: 2325
>>> import gc
>>> gc.mem_free()
37104
>>> gc.mem_alloc()
960

@dpgeorge
Copy link
Member

Really great work, thank you very much!

Rebased, squashed and merged in 53a9b45 and 3117fde

@dpgeorge dpgeorge closed this Oct 10, 2019
@nevercast
Copy link
Contributor

Nice work!

@mcauser mcauser deleted the esp8266-boards branch June 18, 2021 02:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants