Skip to content

[New variant] STM32MP157_DK #717

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
merged 10 commits into from
Nov 15, 2019
Merged

[New variant] STM32MP157_DK #717

merged 10 commits into from
Nov 15, 2019

Conversation

kbumsik
Copy link
Contributor

@kbumsik kbumsik commented Oct 22, 2019

Depends:

Required by: #766

This PR is to add STM32MP157 discovery boards (both DK1 and DK2).

Since MP1 boards are quite different from other board I explain things to consider to review this PR.

For convenience to test, this PR has commits from #605. You can review commits from 83bc63f. Rebased.

Great reference to read: STM32CubeMP1 development guidelines

You can see the variant's README to learn how to use it. Please ask me if you have any questions about the PR, I will modify the commits if needed.


Engineering mode vs Production mode

The M4 coprocessor of STM32MP1 has two operating modes: Engineering mode and Production mode (or normal mode). Engineering mode is for debugging the M4 while disabling the Linux A7 core. In this mode you can use ST-Link to upload and debug the M4, but the M4 doesn't have a flash memory: the firmware will disappear in the next boot. To avoid the confusion to the users I focus on Production mode only and made a necessary tools for Production mode. The new run_arduino_gen.sh tool is explained in Arduino-Tools#47.

In the Production mode, the core clock configuration is done by the Linux/U-Boot host so we need simply ignore related functions like SystemClock_Config(). The new IS_ENGINEERING_BOOT_MODE() from HAL is used to detect the Production mode.
https://github.com/kbumsik/Arduino_Core_STM32/blob/aebcddff59375b4ac53134babc61dd655b028414/variants/STM32MP157_DK/variant.cpp#L147-L149

lock_resources.h and lock_resources.c

Because GPIO ports are shared with the Linux host, a locking mechanism is needed to avoid race conditions. I copied the source directly from the Cube library: 28898e3

GPIOZ and ANA_1:2

The new GPIOZ and ANA_x pins are added. GPIOZ is not special but I modified port/pin definitions since that name was used to indicate the end of GPIO names. The new ANA_1/ANA_2 pins are something like PADC_TEMP but they are physically exposed pins. We don't need to GPIO control for ANA_1/ANA_2 because they are always directly connected to the ADC channels: 442ca6c

pseudo-EEPROM using RETRAM

The M4 core does not have flash. Instead we can use RETRAM to emulate EEPROM library. It have some important limitations that data is not preserved between reboots. The limitations section of the variant's README and 136cf8f#diff-21d65ef266789f937660e766b5fa188aR49 explains the properties and the limitations of RETRAM.

The complete HAL_RCCEx_GetPeriphCLKFreq()

STM32MP1xx's HAL_RCCEx_GetPeriphCLKFreq() now is able to return almost all ptheripheral's clock frequencies. So I tried to make use of this functions as much as I can instead of manually calculate the clock frequencies.

Communication with the main processor

There is no easy way to communicate with the host Linux. The limitations section of the variant's README explains such limitation. I'm working on virtual serial communication using OpenAMP rpmsg framework, but it turns out to be another big change. So I will make a separate PR for virtualIO communication.


This change is Reviewable

@fpistm fpistm added the new variant Add support of new bard label Oct 23, 2019
@kbumsik
Copy link
Contributor Author

kbumsik commented Oct 23, 2019

I have a question regarding developing Virtual Serial feature.

I looked at how USB libraries are compiled since OpenAMP is a middleware library like STM32_USB libraries. As far as I understand it seems that Arduino IDE does not really compile the source files from /system/Middlewares/ST but the source files under /cores/arduino/stm32/usb. Is my understanding correct? Then are files under /system/Middlewares/ST just for references or for placeholders of header files? Should I copy necessary files from /system/Middlewares/OpenAMP to a new directory in /cores/arduino/stm32?

@fpistm
Copy link
Member

fpistm commented Oct 23, 2019

In fact Arduino compile only source files found in core/ folder.
So we wrap needed files in the core by including them. Ex:
https://github.com/stm32duino/Arduino_Core_STM32/blob/master/cores/arduino/stm32/usb/usb_device_core.c

And this allow to update easily the middleware that's why we avoid copy

@kbumsik
Copy link
Contributor Author

kbumsik commented Oct 23, 2019

Oh I see. That's why some of the compiler -I flags points to the source directory of the middleware. Thanks!

@fpistm
Copy link
Member

fpistm commented Oct 23, 2019

Oh I see. That's why some of the compiler -I flags points to the source directory of the middleware. Thanks!

exactly 😉

@kbumsik kbumsik force-pushed the stm32mp1 branch 2 times, most recently from 241510d to b7d9ae3 Compare October 24, 2019 05:59
@fpistm
Copy link
Member

fpistm commented Oct 24, 2019

#605 has been merged.

@kbumsik
Copy link
Contributor Author

kbumsik commented Oct 24, 2019

@fpistm Thanks, I rebased the branch to offer a less messy code view.

@fpistm
Copy link
Member

fpistm commented Oct 24, 2019

@kbumsik
how do you generate the PeripheralPins.c ?

@kbumsik
Copy link
Contributor Author

kbumsik commented Oct 24, 2019

@fpistm
It was months ago, but I slightly fixed genpinmap_arduino.py to produce PeripheralPins.c.
I added some lines to make it recognize ANAx pins and PWR_WKUP pin (the latter seems to be resolved by the recent commit: stm32duino/Arduino_Tools@5d6a7f4). It was a bit hack that works for STM32MP1 only and there seemed to be a better way to solve the problem, so I was hesitated to make a PR for this. Anyway here is the diff of genpinmap_arduino.py I used:

diff --git a/src/genpinmap/genpinmap_arduino.py b/src/genpinmap/genpinmap_arduino.py
index 645b1a8d..5fff18ae 100644
--- a/src/genpinmap/genpinmap_arduino.py
+++ b/src/genpinmap/genpinmap_arduino.py
@@ -851,6 +851,9 @@ def clean_all_lists():
 def parse_pins():
     print(" * Getting pins per Ips...")
     pinregex = r"^(P[A-Z][0-9][0-5]?)"
+    # STM32MP1 has additional pin definitions such as ANA1 for ADC
+    if "STM32MP1" in mcu_file:
+        pinregex = r"^(P[A-Z][0-9][0-5]?|ANA[0-9])"
     itemlist = xml_mcu.getElementsByTagName("Pin")
     for s in itemlist:
         m = re.match(pinregex, s.attributes["Name"].value)
@@ -859,7 +862,11 @@ def parse_pins():
                 m.group(0)[:2] + "_" + m.group(0)[2:]
             )  # pin formatted P<port>_<number>: PF_O
             name = s.attributes["Name"].value.strip()  # full name: "PF0 / OSC_IN"
-            if s.attributes["Type"].value == "I/O":
+            pin_type = s.attributes["Type"].value
+            if pin_type == "I/O":
+                store_pin(pin, name)
+            elif "STM32MP1" in mcu_file and "ANA" in name and pin_type == "MonoIO":
+                pin = "ANA" + "_" + name[3:] # ANA1 will be ANA_1
                 store_pin(pin, name)
             else:
                 continue
@@ -890,6 +897,11 @@ def parse_pins():
                     store_usb(pin, name, sig)
                 if sig.startswith("SD"):
                     store_sd(pin, name, sig)
+                if re.match("STM32MP1", mcu_file):
+                    # In STM32MP1, SYS_WKUP is renamed as PWR_WKUP
+                    if "PWR_" in sig:
+                        sig = sig.replace("PWR_", "SYS_")
+                        store_sys(pin, name, sig)
 
 
 # main

You can ignore the changeset related PWR_WKUP.

@fpistm
Copy link
Member

fpistm commented Oct 24, 2019

Thanks @kbumsik
I've made the update:
stm32duino/Arduino_Tools@f735a44

@cpriouzeau
Copy link

Some remark about README:
README: https://github.com/kbumsik/Arduino_Core_STM32/tree/stm32mp1/variants/STM32MP157_DK

  • For ckermit restriction: the issue are corrected and available since delivery 1.1 (September 2019)

Good work
Regards
Christophe

Copy link
Member

@fpistm fpistm left a comment

Choose a reason for hiding this comment

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

Thanks @kbumsik
This is really a great work. 👍
I've some changes to request.
I've a rebased version of your PR with all my fixes:
https://github.com/fpistm/Arduino_Core_STM32/tree/PR-717-Review

@fpistm
Copy link
Member

fpistm commented Nov 8, 2019

@kbumsik
I've made a clean branch based of your PR and my review.
I've rebase, squash and reorder commit to be more clean:
https://github.com/fpistm/Arduino_Core_STM32/tree/PR-717-ReviewClean

If you agreed this should be fine you update this PR with this one.
Thanks

@kbumsik
Copy link
Contributor Author

kbumsik commented Nov 8, 2019

@fpistm
Thanks for cleaning the commits, you just saved my hours! The commits looks good to me.
I've just added some quick fix and README update. I hope this is the last fix.

Copy link
Member

@fpistm fpistm left a comment

Choose a reason for hiding this comment

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

@kbumsik
Thanks for the update.
Anyway could you squash the 2 fixup commits with the appropriate commits.

f4de5ab with 1393318
and
788b613 with 1ea62c1

Thanks

@kbumsik
Copy link
Contributor Author

kbumsik commented Nov 8, 2019

@fpistm Sure. Done :)

Copy link
Member

@fpistm fpistm left a comment

Choose a reason for hiding this comment

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

LGTM
Still to made some tests before merge and validate stm32duino/Arduino_Tools#47

@fpistm fpistm self-requested a review November 8, 2019 13:53
@fpistm
Copy link
Member

fpistm commented Nov 14, 2019

Hi @kbumsik
I've made several test and it works fine for the main features:

  • SPI
  • I2C
  • Timer
  • USART
    Only the ADC seems not properly handle. I will investigate this.
    Could you squash the 2 last fixup commits to the appropriate ones then I will merge.
    This is a really good STM32MP1 introduction 👏
    I will fix ADC in a further commits.
    I would like to thank you again about your grat job and will review virtio after.

@kbumsik
Copy link
Contributor Author

kbumsik commented Nov 15, 2019

@fpistm Cool, I squashed the fixup commits. Thanks for great reviewing!

@fpistm
Copy link
Member

fpistm commented Nov 15, 2019

stm32duino/Arduino_Tools#47 merged

@fpistm fpistm merged commit ef13395 into stm32duino:master Nov 15, 2019
This was referenced Nov 15, 2019
@ABOSTM
Copy link
Contributor

ABOSTM commented Jan 20, 2020

@arnopo FYI

@Hedda
Copy link

Hedda commented Mar 2, 2020

FYI, STMicro has updated their STM32MP1 Family with models that have faster 800 MHz Cortex-A7 Processors, through the Cortex-M4 core still runs at same 209 MHz speed as previous models.

https://www.cnx-software.com/2020/02/27/stmicro-updates-stm32mp1-family-with-800-mhz-cortex-a7-processors/

https://blog.st.com/mpu-stm32mp1/

https://newsroom.st.com/media-center/press-item.html/p4236.html

@Hedda
Copy link

Hedda commented Feb 12, 2021

More STM32MP1 boards (and SoM modules) are now available:

STM32MP157A-EV1 Evaluation kit with breakout board and STM32MP115X-EVAL evaluation board

https://www.st.com/en/evaluation-tools/stm32mp157a-ev1.html

STM32MP157C-EV1 Evaluation kit with breakout board and STM32MP115X-EVAL evaluation board

https://www.st.com/en/evaluation-tools/stm32mp157c-ev1.html

Seeed Studio ODYSSEY-STM32MP157C SBC based on Seeed Studio SoM-STM32MP157C SoM

https://www.cnx-software.com/2020/01/21/odyssey-stm32mp157c-sbc-feature-stmicro-stm32mp157c-cortex-a7-m4-soc/

Emtrion emSBC-Argon

https://www.cnx-software.com/2019/07/18/emtrion-emsbc-argon-stm32mp1-dual-cortex-a7-m4-processor/

i2Som PanGu board from I2Som:

https://www.cnx-software.com/2019/06/25/pangu-board-stm32mp1-sbc/

MYIR MYD-YA157C development board based on their MYiR MYC-YA157C STM32MP1 CPU Module

https://www.cnx-software.com/2020/01/07/myir-launches-som-development-board-based-on-stm32mp1-microprocessor/

Avenger96 96Boards CE Extended Board Features an STMicro STM32MP1 SoM

https://www.cnx-software.com/2019/02/23/avenger96-96boards-stmicro-stm32mp1-som/

Shiratech Stinger96 board (96Boards board design)

https://www.cnx-software.com/2020/05/15/stinger96-nb-iot-emtc-and-avenger96-96boards-stm32mp1-sbcs-giveaway/

Direct Insight / Ka-Ro STM32MP1 QSMP 1570 / 157C SoM module and development kit with thier reference devboard/devkit:

https://www.cnx-software.com/2020/06/26/linux-powered-stmicro-stm32mp1-solder-down-qfn-style-som-measures-27x27mm/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new variant Add support of new bard
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants