Thanks to visit codestin.com
Credit goes to github.com

Skip to content

mimxrt: Rework flash configuration. #7767

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

Merged

Conversation

alphaFred
Copy link
Contributor

  • Moves definition of BOARD_FLASH_SIZE and other header files related to
    flash configuration into the Makefile.
  • Adds board specific clock_config.h.
  • Adds board.h, pin_mux.h, and peripherals.h as they are
    required by NXP MCU SDK in order to use our own clock_config.h.
  • Renames board specific FlexSPI configuration files.
  • Updates flash frequency of MIMXRT1020_EVK
  • Creates separated flash_config files for QSPI NOR and
    QSPI Hyper flash.
  • Unifies VFS start address to be @ 1M for 1010 and 1020 boards.
  • Unifies 1050EVK boards
  • Adds support to both NOR and HyperFlash on boards with
    both capabilities.
  • Adds automatic FlexRAM initialization to start-up code based on
    linker script and NXP HAL.

With this change the flash configuration is restructured.
This simplifies the configuration process and
provides a better overview of each board's settings. With the integration
of clock_config.h, board.h, pin_mux.h, and peripherals.h we gain better
control of the settings and clock configurations. Furthermore the
implementation of an explicit FlexRAM setup improves the system
performance and allows for performance tuning.

Signed-off-by: Philipp Ebensberger

@alphaFred alphaFred force-pushed the mimxrt/refactoring_flash_config branch 2 times, most recently from cc1a1f3 to a88b94d Compare September 10, 2021 05:57
@robert-hh
Copy link
Contributor

Just a few additional notes on that PR:
This PR looks huge, but is an attempt to clean up the various board file trees to a common structure. Over the time, things got a little bit fuzzy. And so we decided to make this PR. It covers the fact, that the boards can be configured with different flash setting. It also includes a change to make better use of the built-in RAM. That causes most of the added lines of code, because it moves the startup_xxx.s files from the nxp_lib to the port file system. That seems necessary since the RAM re-config has to happen before any RAM is used.

@alphaFred alphaFred force-pushed the mimxrt/refactoring_flash_config branch from a88b94d to 13e9a27 Compare September 10, 2021 06:55
@alphaFred alphaFred marked this pull request as ready for review September 10, 2021 07:52
@@ -0,0 +1,194 @@
#!/usr/bin/env python
"""Evaluate FlexRAM configuration and generate startup code."""
Copy link
Member

Choose a reason for hiding this comment

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

what is the license/copyright of this file?

Copy link
Contributor

Choose a reason for hiding this comment

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

It was written by @alphaFred, so I assume it's MIT, and Philipp will add the appropriate License.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes - I will add the license

Copy link
Member

Choose a reason for hiding this comment

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

please make the style of the license/copyright match existing files, eg tools/pyboard.py and tools/mpy_ld.py (use # at the start of the line)

@dpgeorge
Copy link
Member

Regarding the startup_MIMXRTxxx.S files: in the HAL versions of these files the Reset_Handler function is defined as a weak symbol. So that means you can reimplement just this function in your own code, which is exactly what you need. This is how stm32 works, it uses the HAL's startup code to get the IRQ table, but reimplements Reset_Handler in ports/stm32/resethandler.s. I'd suggest mimxrt also do it this way so that there is less code, and maybe the same resethandler.s (or .S if it needs to use the C preprocessor) can be used for all MCU variants.

Also, why exactly does the clock_config.h file need to be copied out of the HAL into each board directory? As far as I can tell it's copied without change, so why can't it reuse the HAL version?

@alphaFred
Copy link
Contributor Author

Hi @dpgeorge. Thanks for your review.

Regarding your first point - I will give it a try and check if it works for us.

Regarding clock_config.h. This is part of a set of four files (clock_config.h, board.h,peripherals.h,pin_mux.h) which are provided as templates. So far this worked fine for us but with this cleanup I noticed that the board.h defines BOARD_FLASH_SIZE with out #ifdefguard. This is a problem when we want to configure for different flash sizes (e.g. QPSI vs. HyperFlash). To get around that I needed to create my own set of these header files. Since they are all located in one folder I could not easily exclude clock_config.h.

On a side note:
I already have another PR ready which builds on top of this one where we will refactor the clock configuration. in that PR you will see differences in clock_config.h.

@robert-hh
Copy link
Contributor

maybe the same resethandler.s (or .S if it needs to use the C preprocessor) can be used for all MCU variants.

That is indeed the case. I just tested that (and compared the files) and it works for all MCU's I have here.

@alphaFred
Copy link
Contributor Author

@dpgeorge I pushed an update with fixes. Tbh I was not sure about the format of the license statement for the Python script since I could not find a single other Python file in the project which had one. So let me know if it is ok for you 😄

@alphaFred alphaFred force-pushed the mimxrt/refactoring_flash_config branch from b59a909 to 27ecec4 Compare September 13, 2021 19:02
@codecov-commenter
Copy link

codecov-commenter commented Sep 13, 2021

Codecov Report

Merging #7767 (f8bdfad) into master (0a51073) will increase coverage by 0.00%.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #7767   +/-   ##
=======================================
  Coverage   98.24%   98.25%           
=======================================
  Files         154      154           
  Lines       20040    20042    +2     
=======================================
+ Hits        19689    19692    +3     
+ Misses        351      350    -1     
Impacted Files Coverage Δ
py/objlist.c 99.23% <0.00%> (-0.39%) ⬇️
py/runtime.c 99.39% <0.00%> (ø)
py/emitnative.c 99.26% <0.00%> (+<0.01%) ⬆️
py/obj.c 97.22% <0.00%> (+0.39%) ⬆️
py/bc.c 89.69% <0.00%> (+1.03%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0a51073...f8bdfad. Read the comment docs.

@@ -0,0 +1,194 @@
#!/usr/bin/env python
"""Evaluate FlexRAM configuration and generate startup code."""
Copy link
Member

Choose a reason for hiding this comment

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

please make the style of the license/copyright match existing files, eg tools/pyboard.py and tools/mpy_ld.py (use # at the start of the line)

ldr r2, =__data_start__
ldr r3, =__data_end__

#ifdef __PERFORMANCE_IMPLEMENTATION
Copy link
Member

Choose a reason for hiding this comment

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

The difference in code size between __PERFORMANCE_IMPLEMENTATION enabled and disabled is very small, and these chips have a huge amount of flash, so I think it's simpler/cleaner to just unconditionally use the performance version of the code (ie remove the other code).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, I tried it out now but it does not work. Even when just compiling with __PERFORMANCE_IMPLEMENTATION defined, MicroPython crashes.
If you are ok with it, let us merge it as it is and we will look into it later and fix it.

@alphaFred
Copy link
Contributor Author

@dpgeorge I pushed an update with the required fixes (:smile: )

@alphaFred alphaFred force-pushed the mimxrt/refactoring_flash_config branch 2 times, most recently from c1c76b7 to f8bdfad Compare September 14, 2021 09:17
@alphaFred
Copy link
Contributor Author

@dpgeorge @robert-hh
I pushed an update with an update to code formatting (added "ports/mimxrt/**/*.[ch]", to tools/codeformat.pyas in #7785) and ran the formatting on all the files in mimxrt port. Should be indentical with #7785 now.

Btw. whenever I execute codeformat.py it also creates changes in other files:

	modified:   ../../extmod/machine_i2c.c
	modified:   ../../extmod/vfs_lfsx.c
	modified:   ../stm32/mpconfigport.h
	modified:   ../unix/mpconfigport.h
	modified:   ../../py/compile.

@dpgeorge
Copy link
Member

Btw. whenever I execute codeformat.py it also creates changes in other files:

It's not showing on the CI here, so could be your local uncrustify version.

@alphaFred
Copy link
Contributor Author

Ok, then never mind :-)

@dpgeorge
Copy link
Member

@alphaFred at this stage I'd still need to rebase it and reword the commit message (to something like `mimxrt: Rework flash configuration." to get the tense correct). But feel free to do that yourself if you like.

@alphaFred
Copy link
Contributor Author

Ok. I hope I get the tense right the next time at first try 😂.

- Moves definition of BOARD_FLASH_SIZE and other header files related to
	flash configuration into the Makefile.
- Adds board specific clock_config.h.
- Adds board.h, pin_mux.h, and peripherals.h as they are
	required by NXP MCU SDK in order to use our own clock_config.h.
- Renames board specific FlexSPI configuration files.
- Updates flash frequency of MIMXRT1020_EVK
- Creates separated flash_config files for QSPI NOR and
	QSPI Hyper flash.
- Unifies VFS start address to be @ 1M for 1010 and 1020 boards.
- Unifies 1050EVK boards
- Adds support to both NOR and HyperFlash on boards with
	both capabilities.
- Adds automatic FlexRAM initialization to start-up code based on
	linker script and NXP HAL.
- Applies code formatting to all files in mimxrt port.

With this change the flash configuration is restructured and
organized. This simplifies the configuration process and
provides a better overview of each board's settings. With the integration
of clock_config.h, board.h, pin_mux.h, and peripherals.h we gain better
control of the settings and clock configurations. Furthermore the
implementation of an explicit FlexRAM setup improves the system
performance and allows for performance tuning.

Signed-off-by: Philipp Ebensberger
@alphaFred alphaFred force-pushed the mimxrt/refactoring_flash_config branch from f8bdfad to 0d7366c Compare September 14, 2021 11:55
@alphaFred
Copy link
Contributor Author

@dpgeorge
Ok, I fixed your latest comments, rebased and fixed the title of the commit. Should be good to go. Many thanks for your quick review.

@alphaFred alphaFred changed the title mimxrt: Rework of flash configuration. mimxrt: Rework flash configuration. Sep 14, 2021
@dpgeorge dpgeorge merged commit 0d7366c into micropython:master Sep 14, 2021
@dpgeorge
Copy link
Member

Merged!

@alphaFred alphaFred deleted the mimxrt/refactoring_flash_config branch September 14, 2021 14:33
tannewt added a commit to tannewt/circuitpython that referenced this pull request Mar 22, 2023
Make set_stack_limit respect fixed stack
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