wiki:Wsl2Build

WSL2 環境で MicroPython の Build

ここでは、Windows PC で、STM32系の市販されているボードに MicroPython を実装する手順を記録します

WSL2 (Ubuntu) のインストール

STM32系のARM用のコンパイルには、この環境が最適のようです この記事がていねい

  • Windows11 の右クリックで[ターミナル(管理者)]を起動
    PS C:\Users\user> wsl --install
    
  • 以下は、インストールが終わって、再起動した直後
    Ubuntu は既にインストールされています。
    Ubuntu を起動しています...
    Installing, this may take a few minutes...
    Please create a default UNIX user account. The username does not need to match your Windows username.
    For more information visit: https://aka.ms/wslusers
    Enter new UNIX username: user1
    New password:<psword>
    Retype new password:<psword>
    passwd: password updated successfully
    Installation successful!
    To run a command as administrator (user "root"), use "sudo <command>".
    See "man sudo_root" for details.
    
    Welcome to Ubuntu 22.04.2 LTS (GNU/Linux 5.15.90.1-microsoft-standard-WSL2 x86_64)
    
     * Documentation:  https://help.ubuntu.com
     * Management:     https://landscape.canonical.com
     * Support:        https://ubuntu.com/advantage
    
    
    This message is shown once a day. To disable it please create the
    /home/user1/.hushlogin file.
    user1@PCHOSTNAME:~$
    

WSL2上のクロスコンパイル環境のセットアップ

  • https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads
  • gcc-arm-11.2-2022.02-x86_64-arm-none-eabi.tar.xzC:/ST/ に、ダウンロードする
  • WSL2 で、展開しセットアップ
    user1@PCHOSTNAME:~$ ll /mnt/c/ST/gcc-arm-11.2-2022.02-x86_64-arm-none-eabi.tar.xz
    -rwxrwxrwx 1 user1 user1 490927032 Jun  4 17:30 /mnt/c/ST/gcc-arm-11.2-2022.02-x86_64-arm-none-eabi.tar.xz*
    user1@PCHOSTNAME:~$ sudo tar xJf /mnt/c/ST/arm-gnu-toolchain-12.2.mpacbti-rel1-x86_64-arm-none-eabi.tar.xz
    user1@PCHOSTNAME:~$ ll gcc-arm-11.2-2022.02-x86_64-arm-none-eabi/
    total 40
    drwxr-xr-x 8   802   802 4096 Feb  3  2022 ./
    drwxr-x--- 5 user1 user1 4096 Jun  4 17:35 ../
    -rw-r--r-- 1   802   802 4572 Feb  3  2022 11.2-2022.02-x86_64-arm-none-eabi-manifest.txt
    drwxr-xr-x 5   802   802 4096 Feb  2  2022 arm-none-eabi/
    drwxr-xr-x 2   802   802 4096 Feb  2  2022 bin/
    drwxr-xr-x 3   802   802 4096 Feb  2  2022 include/
    drwxr-xr-x 4   802   802 4096 Feb  2  2022 lib/
    drwxr-xr-x 3   802   802 4096 Feb  2  2022 libexec/
    drwxr-xr-x 8   802   802 4096 Feb  3  2022 share/
    user1@PCHOSTNAME:~$ mkdir gcc-arm-none-eabi
    user1@PCHOSTNAME:~$ mkdir gcc-arm-none-eabi/DEBIAN
    user1@PCHOSTNAME:~$ mkdir gcc-arm-none-eabi/usr
    user1@PCHOSTNAME:~$ echo "Package: gcc-arm-none-eabi" > gcc-arm-none-eabi/DEBIAN/control
    user1@PCHOSTNAME:~$ echo "Version: 11.2-2022.02" >> gcc-arm-none-eabi/DEBIAN/control
    user1@PCHOSTNAME:~$ echo "Architecture: amd64" >> gcc-arm-none-eabi/DEBIAN/control
    user1@PCHOSTNAME:~$ echo "Maintainer: maintainer" >> gcc-arm-none-eabi/DEBIAN/control
    user1@PCHOSTNAME:~$ echo "Description: Arm Embedded toolchain" >> gcc-arm-none-eabi/DEBIAN/control
    user1@PCHOSTNAME:~$ cat gcc-arm-none-eabi/DEBIAN/control
    Package: gcc-arm-none-eabi
    Version: 11.2-2022.02
    Architecture: amd64
    Maintainer: maintainer
    Description: Arm Embedded toolchain
    user1@PCHOSTNAME:~$ sudo mv gcc-arm-11.2-2022.02-x86_64-arm-none-eabi/* gcc-arm-none-eabi/usr/
    user1@PCHOSTNAME:~$ ll gcc-arm-none-eabi/usr/
    drwxr-xr-x 8 user1 user1 4096 Jun  4 17:48 ./
    drwxr-xr-x 4 user1 user1 4096 Jun  4 17:39 ../
    -rw-r--r-- 1   802   802 4572 Feb  3  2022 11.2-2022.02-x86_64-arm-none-eabi-manifest.txt
    drwxr-xr-x 5   802   802 4096 Feb  2  2022 arm-none-eabi/
    drwxr-xr-x 2   802   802 4096 Feb  2  2022 bin/
    drwxr-xr-x 3   802   802 4096 Feb  2  2022 include/
    drwxr-xr-x 4   802   802 4096 Feb  2  2022 lib/
    drwxr-xr-x 3   802   802 4096 Feb  2  2022 libexec/
    drwxr-xr-x 8   802   802 4096 Feb  3  2022 share/
    user1@PCHOSTNAME:~$ dpkg-deb --build --root-owner-group gcc-arm-none-eabi
    dpkg-deb: building package 'gcc-arm-none-eabi' in 'gcc-arm-none-eabi.deb'.
    user1@PCHOSTNAME:~$ sudo apt install ./gcc-arm-none-eabi.deb -y --allow-downgrades
    [sudo] password for user1:
    Reading package lists... Done
    Building dependency tree... Done
    Reading state information... Done
    Note, selecting 'gcc-arm-none-eabi' instead of './gcc-arm-none-eabi.deb'
    The following NEW packages will be installed:
      gcc-arm-none-eabi
    0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
    Need to get 0 B/568 MB of archives.
    After this operation, 0 B of additional disk space will be used.
    Get:1 /home/user1/gcc-arm-none-eabi.deb gcc-arm-none-eabi amd64 11.2-2022.02 [568 MB]
    Selecting previously unselected package gcc-arm-none-eabi.
    (Reading database ... 24137 files and directories currently installed.)
    Preparing to unpack .../user1/gcc-arm-none-eabi.deb ...
    Unpacking gcc-arm-none-eabi (11.2-2022.02) ...
    Setting up gcc-arm-none-eabi (11.2-2022.02) ...
    Processing triggers for install-info (6.8-4build1) ...
    Processing triggers for man-db (2.10.2-1) ...
    N: Download is performed unsandboxed as root as file '/home/user1/gcc-arm-none-eabi.deb' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied)
    user1@PCHOSTNAME:~$ arm-none-eabi-gcc --version
    arm-none-eabi-gcc (GNU Toolchain for the Arm Architecture 11.2-2022.02 (arm-11.14)) 11.2.1 20220111
    Copyright (C) 2021 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    
    user1@PCHOSTNAME:~$ 
    

git で、MicroPython のソースを展開

  • git で、 github から clone
    user1@PCHOSTNAME:~$ git clone -b master https://github.com/micropython/micropython.git
    Cloning into 'micropython'...
    remote: Enumerating objects: 109194, done.
    remote: Counting objects: 100% (36573/36573), done.
    remote: Compressing objects: 100% (3601/3601), done.
    remote: Total 109194 (delta 34707), reused 33068 (delta 32970), pack-reused 72621
    Receiving objects: 100% (109194/109194), 55.84 MiB | 7.79 MiB/s, done.
    Resolving deltas: 100% (81706/81706), done.
    user1@PCHOSTNAME:~$ ll
    total 554408
    drwxr-xr-x  8   802   802      4096 Mar 14 17:20 arm-gnu-toolchain-12.2.mpacbti-rel1-x86_64-arm-none-eabi/
    drwxr-xr-x  2   802   802      4096 Jun  4 17:48 gcc-arm-11.2-2022.02-x86_64-arm-none-eabi/
    drwxr-xr-x  4 user1 user1      4096 Jun  4 17:39 gcc-arm-none-eabi/
    -rw-r--r--  1 user1 user1 567656490 Jun  4 18:08 gcc-arm-none-eabi.deb
    drwxr-xr-x 16 user1 user1      4096 Jun  5 10:12 micropython/
    user1@PCHOSTNAME:~$ cd micropython/
    user1@PCHOSTNAME:~/micropython$ ll
    total 164
    -rw-r--r--  1 user1 user1 43236 Jun  5 10:12 ACKNOWLEDGEMENTS
    -rw-r--r--  1 user1 user1 11477 Jun  5 10:12 CODECONVENTIONS.md
    -rw-r--r--  1 user1 user1  2640 Jun  5 10:12 CODEOFCONDUCT.md
    -rw-r--r--  1 user1 user1   357 Jun  5 10:12 CONTRIBUTING.md
    -rw-r--r--  1 user1 user1  3247 Jun  5 10:12 LICENSE
    -rw-r--r--  1 user1 user1  7585 Jun  5 10:12 README.md
    drwxr-xr-x 19 user1 user1  4096 Jun  5 10:12 docs/
    drwxr-xr-x  8 user1 user1  4096 Jun  5 10:12 drivers/
    drwxr-xr-x 11 user1 user1  4096 Jun  5 10:12 examples/
    drwxr-xr-x  8 user1 user1  4096 Jun  5 10:12 extmod/
    drwxr-xr-x 30 user1 user1  4096 Jun  5 10:12 lib/
    drwxr-xr-x  2 user1 user1  4096 Jun  5 10:12 logo/
    drwxr-xr-x  3 user1 user1  4096 Jun  5 10:12 mpy-cross/
    drwxr-xr-x 22 user1 user1  4096 Jun  5 10:12 ports/
    drwxr-xr-x  2 user1 user1  4096 Jun  5 10:12 py/
    -rw-r--r--  1 user1 user1   824 Jun  5 10:12 pyproject.toml
    drwxr-xr-x 10 user1 user1  4096 Jun  5 10:12 shared/
    drwxr-xr-x 31 user1 user1  4096 Jun  5 10:12 tests/
    drwxr-xr-x  4 user1 user1  4096 Jun  5 10:12 tools/
    user1@PCHOSTNAME:~/micropython$ 
    
Last modified 8 months ago Last modified on Apr 14, 2024, 12:12:25 PM
Note: See TracWiki for help on using the wiki.