Skip to main content
Graduate II
April 8, 2024
Question

STM32 VS Code Extension and Devcontainer

  • April 8, 2024
  • 9 replies
  • 13022 views

I am a happy VSCode developer using docker devcontainers to create an easily reproducible environment for development. I am struggling with a strange bug with the "STM32 VS Code Extension" (v2.0.1).

If I try to access it, after opening the container, I get the following error:
"Cannot activate the 'STM32 VS Code Extension' extension because it depends on the 'C/C++ Extension Pack' extension, which is not loaded. Would you like to reload the window to load the extension?"

This is strange because the C/C++ Extension Pack is loaded and part of my dev container.

I have the option to "Reload Window", but hitting it only results in a reload and the same message popping back up.

Has anyone been able to use this vscode extension inside a devcontainer?

    This topic has been closed for replies.

    9 replies

    Technical Moderator
    April 15, 2024

    Hi @pcb 

    we are currently trying to reproduce the issue, we will keep you informed.

     

    Technical Moderator
    April 18, 2024

    Hi @pcb 

    Could you please attach the content of 'output' 'debug console' and 'terminal' windows when you are getting the issue please ? 

    pcbAuthor
    Graduate II
    April 18, 2024

    Thank you for looking into this, @Nawres GHARBI 

    "Debug Console" and "Terminal" are both empty, no text there.

    See attached photo.

    Visitor II
    April 22, 2024

    Same problem here:

    mongolracer_0-1713788315704.png

    reinstalled, rebooted etc etc.

    Technical Moderator
    April 25, 2024

    hello @pcb @mongolracer 

    could you please follow the steps in this link and give your feedback

    https://github.com/microsoft/vscode-python/issues/15972

    pcbAuthor
    Graduate II
    April 26, 2024

    @Nawres GHARBI I don't understand what you want me to do here.

    Please elaborate.

    I have Jupyter, pylance, and python extensions in vscode and STM32 VS Code extension works.

    In my devcontainer I have none of them installed, the there the STM32 VS Code extension does not work.

    Visitor II
    April 30, 2024

    I'm having the same issue.  It looks like the STM32 VS Code extension is installing locally instead of in the container.  Since C/C++ extension is installed in the container, STM32 VS Code extension doesn't see it.  

    Ideally, STM32 VS Code Extension and STM32CubeMX should be in the container so we can generate code to the source directory in the container.  That way we don't have to make the source directory available to the host (major performance hit while compiling), or sync it through a remote GIT repo (creates unnecessary commits, and add an unnecessary step to the process).  

    kmcwithey_0-1714486115202.png

     

    Explorer
    May 22, 2024

    I'm having the same issue. Any News?

    Visitor II
    July 1, 2024

    Experiencing the same issue. I think it it a problem of the STM32 VS Code Extension.

    It is stil not fixed by now.

    Docker 27.0.2, Run container in privileged mode.

    kestrel_2-1719853992086.png

     

     

    Explorer
    July 11, 2024

    I was able to get this error to go away if i changed my profile to "Default" which doesnt have the STM32 extension on it

    sslebie_0-1720736482768.png

     

    Explorer
    July 11, 2024

    Yeah by doing that I was able to install the STM32CubeCLT, build my project, and properly generate an elf file.

     

    I'm wondering if you just need the STM32 VS Code Extension not to be installed on the local host. I'm going to work on getting the Dockerfile setup properly so that the image can fully build.

     

    Do you know how to pass a USB device (The STLink Debugger tool) from Windows into the Docker Image?

    Visitor II
    July 11, 2024

    I only have the "Default' profile. And since it works very well on the host machine, I think it is not the issue you have suggested. 

     

    kestrel_1-1720740520119.png

    Image from Visual Studio Code. Developing inside a Container.

    And due to the way VSCode extension works, the host machine must have the extension installed to use it inside the container. Therefore, I think that the secons issue is also not the case I am experiencing now.

    I also attach the Dockerfile I used to build an image. The entrypoint.sh is just a simple "bash -c sleep infinity".

     

     

    RG BASEIMAGE
    ARG BASETAG
    
    # STAGE FOR CACHING APT PACKAGE LIST
    FROM ${BASEIMAGE}:${BASETAG} AS stage_apt
    
    SHELL ["/bin/bash", "-o", "pipefail", "-c"]
    
    ENV \
     DEBIAN_FRONTEND=noninteractive \
     LANG=C.UTF-8 \
     LC_ALL=C.UTF-8
    
    RUN \
     rm -rf /etc/apt/apt.conf.d/docker-clean \
    	&& echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache \
    	&& apt-get update
    
    # STAGE FOR INSTALLING APT DEPENDENCIES
    FROM ${BASEIMAGE}:${BASETAG} AS stage_deps
    
    SHELL ["/bin/bash", "-o", "pipefail", "-c"]
    
    ENV \
     DEBIAN_FRONTEND=noninteractive \
     LANG=C.UTF-8 \
     LC_ALL=C.UTF-8 \
     LICENSE_ALREADY_ACCEPTED=1 \
     JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
    
    COPY aptDeps.txt /tmp/aptDeps.txt
    
    # INSTALL APT DEPENDENCIES USING CACHE OF stage_apt
    RUN \
     --mount=type=cache,target=/var/cache/apt,from=stage_apt,source=/var/cache/apt \
     --mount=type=cache,target=/var/lib/apt,from=stage_apt,source=/var/lib/apt \
     --mount=type=cache,target=/etc/apt/sources.list.d,from=stage_apt,source=/etc/apt/sources.list.d \
    	apt-get install --no-install-recommends -y $(cat /tmp/aptDeps.txt) \
     && rm -rf /tmp/*
    
    COPY \
     resource/en.st-stm32cubeclt_1.12.1_16088_20230420_1057_amd64.deb_bundle.sh.zip \
     /tmp/en.st-stm32cubeclt_1.12.1_16088_20230420_1057_amd64.deb_bundle.sh.zip
    
    # INSTALL STM32CUBECTL
    RUN \
     --mount=type=cache,target=/var/cache/apt,from=stage_apt,source=/var/cache/apt \
     --mount=type=cache,target=/var/lib/apt,from=stage_apt,source=/var/lib/apt \
     --mount=type=cache,target=/etc/apt/sources.list.d,from=stage_apt,source=/etc/apt/sources.list.d \
     unzip -q /tmp/en.st-stm32cubeclt_1.12.1_16088_20230420_1057_amd64.deb_bundle.sh.zip -d /tmp/stm32cubeclt \
     && chmod +x /tmp/stm32cubeclt/st-stm32cubeclt_1.12.1_16088_20230420_1057_amd64.deb_bundle.sh \
     && /tmp/stm32cubeclt/st-stm32cubeclt_1.12.1_16088_20230420_1057_amd64.deb_bundle.sh --target /tmp/stm32cubeclt/debfiles --noexec \
     && apt-get install -y /tmp/stm32cubeclt/debfiles/*.deb \
     && chmod 755 -R /opt/st/stm32cubeclt_1.12.1 \
     && rm -rf /tmp/*
    
    COPY \
     resource/en.stm32cubemx-lin-v6-8-1.zip \
     /tmp/en.stm32cubemx-lin-v6-8-1.zip
    
    COPY \
     resource/auto-install-cubemx.xml \
     /tmp/auto-install-cubemx.xml
    
    # INSTALL STM32CUBEMX
    RUN \
     unzip -q /tmp/en.stm32cubemx-lin-v6-8-1.zip -d /tmp/stm32cubemx \
     && chmod +x /tmp/stm32cubemx/SetupSTM32CubeMX-6.8.1 \
     && /tmp/stm32cubemx/SetupSTM32CubeMX-6.8.1 /tmp/auto-install-cubemx.xml \
     && chmod 755 -R /usr/local/STMicroelectronics/STM32Cube/STM32CubeMX/jre \
     && rm -rf /tmp/*
    
    COPY \
     resource/en.st-mcu-finderlin-v6-0-0.zip \
     /tmp/en.st-mcu-finderlin-v6-0-0.zip
    
    COPY \
     resource/auto-install-stm-mcu-finder.xml \
     /tmp/auto-install-stm-mcu-finder.xml
    
    # INSTALL STMMCUFINDER
    RUN \
     unzip -q /tmp/en.st-mcu-finderlin-v6-0-0.zip -d /tmp/st-mcu-finderlin \
     && /tmp/st-mcu-finderlin/SetupSTMCUFinder-6.0.0 /tmp/auto-install-stm-mcu-finder.xml \
     && chmod 755 -R /usr/local/STMicroelectronics/STMCUFinder/jre \
     && rm -rf /tmp/*
    
    COPY \
     resource/en.st-stm32cubeide_1.12.1_16088_20230420_1057_amd64.sh.zip \
     /tmp/en.st-stm32cubeide_1.12.1_16088_20230420_1057_amd64.sh.zip
    
    # INSTALL STM32CUBEIDE
    RUN \
     unzip -q /tmp/en.st-stm32cubeide_1.12.1_16088_20230420_1057_amd64.sh.zip -d /tmp/stm32cubeide \
     && chmod +x /tmp/stm32cubeide/st-stm32cubeide_1.12.1_16088_20230420_1057_amd64.sh \
     && /tmp/stm32cubeide/st-stm32cubeide_1.12.1_16088_20230420_1057_amd64.sh --target /tmp/stm32cubeide/debfiles --noexec \
     && sed -i '23,43d' /tmp/stm32cubeide/debfiles/install_as_root.sh
    
    WORKDIR /tmp/stm32cubeide/debfiles
    
    RUN \
     /tmp/stm32cubeide/debfiles/setup.sh /opt/st/stm32cubeide_1.12.1 \
     && chmod 755 -R /opt/st/stm32cubeide_1.12.1 \
     && rm -rf /tmp/*
    
    WORKDIR /
    
    # ADD NON-ROOT USER user FOR RUNNING THE WEBUI
    RUN \
     groupadd user \
     && useradd -ms /bin/bash user -g user \
     && echo "user ALL=NOPASSWD: ALL" >> /etc/sudoers
    
    USER user
    WORKDIR /home/user
    
    RUN \
     ln -s /usr/local/STMicroelectronics/STM32Cube/STM32CubeMX /home/user/STM32CubeMX \
     && ln -s /usr/local/STMicroelectronics/STMCUFinder /home/user/STMCUFinder \
     && ln -s /opt/st/stm32cubeide_1.12.1 /home/user/STM32CubeIDE \
     && ln -s /opt/st/stm32cubeclt_1.12.1 /home/user/STM32CubeCLT
    
    COPY entrypoint.sh /usr/local/bin/entrypoint.sh
    
    ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

     

     

    Paths will be:

    • CubeMX: /home/user/STM32CubeMX/STM32CubeMX
    • CubeCLT: /opt/st/stm32cubeclt_1.12.1
    • STMCUFinder: /home/user/STMCUFinder/STMCUFinder

    In order to pass the USB device from the WIndows host to the docker container running on the hyper-V, the method I can think of is to use a docker running on WSL. Through USBIP, you can pass the USB device attached to the Windows host to the client on the WSL session.

    After this, passing the USB device on the WSL host to the docker container through "device" option or volume mount with privileged flag will work. However, I can't think of the working way for the docker container running directly on the Hyper-V environment. I don't know which docker environment is the case of yours, but if it is the case of the latter one, I think it would be better to use a docker running on WSL.

    By the way, I work on the Ubuntu instead of the WSL or Docker Desktop on Windows. I personally have bad user experience for USBIP or equivalent solutions when working on hardware-driven devices.

     

    Ah, I think the version might be the issue for my case. The extension recommends CubeCLT v1.15.0 and version of other packaged to be higher.

    Explorer
    July 13, 2024

    I was able to get a simple Nucleo Project built and running through the Dev Container!

     

    I had to pass the STLink through WSL like you suggested. I'm working on refining the Docker Image to include all the supporting applications and trying to streamline the workflow so I can actually start using this and sharing it!