{"componentChunkName":"component---src-templates-blog-post-js","path":"/posts/stm32discovery_6/","result":{"data":{"markdownRemark":{"html":"<p>I've fully switched over ot using mbed compile tools on mbed-cli, which does drastically simplify the GCC compile process. In my most recent update, which I have now tagged v1 on the <code>stm32_discovery_mbed</code> repository, I have the LED control of the discovery board over BLE. This code was copied from another repository, and took a little finagling to get it to work. Turns out, a lot of the newer mbed-os compile scripts run on python3, since python 2 is deprecated.</p>\n<p>I decided to create a Dockerfile which allows others to compile the code with the same environment. Ultimately, there is a messy step which requires copying over a \"tools\" folder to replace the one from the outdated mbed-os version.</p>\n<p>As you can see from the Dockerfile I have (copied below), I am following the mbed recommended Dockerfile build, but I needed to add an additional line command in my <code>fixes.sh</code> bash script to overwrite the outdated compile script.</p>\n<pre><code># ------------------------------------------------------------------------------\n# Pull base image\nFROM ubuntu:20.04\n\n\n# ------------------------------------------------------------------------------\n# Arguments\nARG WORKDIR=/root\nARG MBED_OS_VER=master\n\n# ------------------------------------------------------------------------------\n# Install tools via apt\nENV DEBIAN_FRONTEND=noninteractive\nRUN apt -y update &#x26;&#x26; \\\n    apt -y install git \\\n    wget \\\n    python3 \\\n    python3-dev \\\n    python3-setuptools \\\n    python3-usb \\\n    python3-pip \\\n    software-properties-common \\\n    build-essential \\\n    cmake \\\n    astyle \\\n    mercurial \\\n    ninja-build \\\n    libssl-dev \\\n    cargo \\\n    &#x26;&#x26; apt clean &#x26;&#x26; rm -rf /var/lib/apt/lists\n\n# Cmake (Mbed OS requires >=3.19.0-rc3 version which is not available in Ubuntu 20.04 repository)\nRUN set -x \\\n    &#x26;&#x26; (cd /tmp \\\n    &#x26;&#x26; [ \"$(uname -m)\" = \"aarch64\" ] &#x26;&#x26; \\\n        CMAKE_SCRIPT=\"cmake-3.19.3-Linux-aarch64.sh\" || \\\n        CMAKE_SCRIPT=\"cmake-3.19.3-Linux-x86_64.sh\" \\  \n    &#x26;&#x26; wget --progress=dot:giga https://github.com/Kitware/CMake/releases/download/v3.19.3/${CMAKE_SCRIPT} \\\n    &#x26;&#x26; sh ${CMAKE_SCRIPT} --exclude-subdir --prefix=/usr/local \\\n    &#x26;&#x26; rm -rf ${CMAKE_SCRIPT}) \\\n    &#x26;&#x26; exec bash \\\n    &#x26;&#x26; : # last line\n\n# ------------------------------------------------------------------------------\n# Install Python modules (which are not included in requirements.txt)\nRUN pip3 install -U \\\n    mbed-cli \\\n    mbed-tools\n\n# Set up mbed environment\nWORKDIR /tmp/\nRUN wget https://github.com/ARMmbed/mbed-os/raw/${MBED_OS_VER}/requirements.txt &#x26;&#x26; \\\n    pip3 install -r requirements.txt &#x26;&#x26; \\\n    rm requirements.txt\n\n# ------------------------------------------------------------------------------\n# Install arm-none-eabi-gcc\nWORKDIR /opt/mbed-os-toolchain\nRUN [ \"$(uname -m)\" = \"aarch64\" ] &#x26;&#x26; \\\n        TARBALL=\"gcc-arm-none-eabi-9-2019-q4-major-aarch64-linux.tar.bz2\" || \\\n        TARBALL=\"gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2\" &#x26;&#x26; \\\n    wget -q https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2019q4/RC2.1/${TARBALL} &#x26;&#x26; \\\n    tar -xjf ${TARBALL} &#x26;&#x26; \\\n    rm ${TARBALL}\n\n# ------------------------------------------------------------------------------\n# Configure mbed build system\nRUN set -x \\\n    &#x26;&#x26; mbed config -G GCC_ARM_PATH /opt/mbed-os-toolchain/gcc-arm-none-eabi-9-2019-q4-major/bin/ \\\n    &#x26;&#x26; mbed toolchain -G -s GCC_ARM \\\n    &#x26;&#x26; : # last line\n\n# ------------------------------------------------------------------------------\n# Configure environment variables\nENV MBED_GCC_ARM_PATH=/opt/mbed-os-toolchain/gcc-arm-none-eabi-9-2019-q4-major/bin/\nENV PATH=\"${PATH}:${MBED_GCC_ARM_PATH}\"\n\n# ------------------------------------------------------------------------------\n# Display and save environment settings\nRUN python3 --version | tee env_settings &#x26;&#x26; \\\n    arm-none-eabi-gcc --version | tee -a env_settings &#x26;&#x26; \\\n    (echo -n 'mbed-cli ' &#x26;&#x26; mbed --version) | tee -a env_settings &#x26;&#x26; \\\n    (echo -n 'mbed-greentea ' &#x26;&#x26; mbedgt --version) | tee -a env_settings &#x26;&#x26; \\\n    (echo -n 'mbed-host-tests ' &#x26;&#x26; mbedhtrun --version) | tee -a env_settings &#x26;&#x26; \\\n    (echo -n 'mbed-tools ' &#x26;&#x26; mbed-tools --version) | tee -a env_settings\n\nWORKDIR /work\n\n# Copy all files into a directory called \"work\"\nADD . /work\n\n# Run fixes.sh, which replaces the \"tools\" folder with an updated folder\nRUN chmod u+x fixes.sh &#x26;&#x26; \\\n    ./fixes.sh\n</code></pre>\n<p>Next steps: add in sensor readings to BLE, try upgrading to the latest Mbed-OS</p>","frontmatter":{"title":"B-L475E-IOT01A - Setting up environment in Docker"}}},"pageContext":{"slug":"/posts/stm32discovery_6/"}},"staticQueryHashes":["3649515864"]}