diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..051f7e5 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,26 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile +{ + "name": "stm32_devcontainer", + "dockerComposeFile": "../docker/docker-compose.yaml", + "service": "stm32_devcontainer", + "workspaceFolder": "/home/stm32_devcontainer", + "shutdownAction": "stopCompose", + "customizations": { + "vscode": { + "extensions": [ + "ms-vscode.cpptools", + "waderyan.gitblame", + "ms-vscode.cpptools-themes", + "twxs.cmake", + "donjayamanne.python-extension-pack", + "ms-iot.vscode-ros", + "mhutchie.git-graph", + "arturock.gitstash", + "bierner.markdown-mermaid", + "marus25.cortex-debug", + "tomoki1207.pdf" + ] + } + } +} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c9899bd --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +build +example +*.zip \ No newline at end of file diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..b6b707b --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,26 @@ +{ + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/${PROJECT_NAME_VN200}/Converter/Inc/**", + "${workspaceFolder}/${PROJECT_NAME_VN200}/Core/Inc/**", + "${workspaceFolder}/${PROJECT_NAME_VN200}/Drivers/STM32F3xx_HAL_Driver/Inc/**", + "${workspaceFolder}/${PROJECT_NAME_VN200}/Drivers/CMSIS/Device/ST/STM32F3xx/Include", + "${workspaceFolder}/${PROJECT_NAME_VN200}/Drivers/CMSIS/Include", + "/usr/local/include/**" + ], + "defines": [ + "__cplusplus", + "USE_HAL_DRIVER", + "STM32F302xC", // Change this to your MCU for correct linting + "DEBUG" + ], + "compilerPath": "/usr/bin/gcc", + "cStandard": "c17", + "cppStandard": "gnu++17", + "intelliSenseMode": "linux-gcc-x64" + } + ], + "version": 4, +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..ba079c8 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,19 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "F3 - VN200", + "type": "cortex-debug", + "request": "launch", + "servertype": "openocd", + "cwd": "${workspaceRoot}/${env:PROJECT_NAME_VN200}", + "executable": "${workspaceRoot}/${env:PROJECT_NAME_VN200}/build/${env:PROJECT_NAME_VN200}.elf", + "configFiles": [ + "/usr/share/openocd/scripts/interface/stlink.cfg", + "/home/stm32_devcontainer/.vscode/stm32f3x_custom.cfg" + ], + //"svdFile": "${workspaceRoot}/path/to/your.svd", + "preLaunchTask": "build_vn200" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..65e1690 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,13 @@ +{ + "files.associations": { + "main.h": "cpp", + "main.c": "cpp", + "test.h": "cpp", + "test.cpp": "cpp", + "array": "cpp", + "string": "cpp", + "string_view": "cpp", + "ranges": "cpp" + }, + "C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: Google, IndentWidth: 4, ColumnLimit: 150}" +} \ No newline at end of file diff --git a/.vscode/stm32f3x_custom.cfg b/.vscode/stm32f3x_custom.cfg new file mode 100644 index 0000000..18f3f7a --- /dev/null +++ b/.vscode/stm32f3x_custom.cfg @@ -0,0 +1,109 @@ +# script for stm32f3x family + +# +# stm32 devices support both JTAG and SWD transports. +# +source [find target/swj-dp.tcl] +source [find mem_helper.tcl] + +if { [info exists CHIPNAME] } { + set _CHIPNAME $CHIPNAME +} else { + set _CHIPNAME stm32f3x +} + +set _ENDIAN little + +# Work-area is a space in RAM used for flash programming +# By default use 16kB +if { [info exists WORKAREASIZE] } { + set _WORKAREASIZE $WORKAREASIZE +} else { + set _WORKAREASIZE 0x4000 +} + +# JTAG speed should be <= F_CPU/6. F_CPU after reset is 8MHz, so use F_JTAG = 1MHz +# +# Since we may be running of an RC oscilator, we crank down the speed a +# bit more to be on the safe side. Perhaps superstition, but if are +# running off a crystal, we can run closer to the limit. Note +# that there can be a pretty wide band where things are more or less stable. +adapter speed 140 + +adapter srst delay 100 +if {[using_jtag]} { + jtag_ntrst_delay 100 +} + +#jtag scan chain +if { [info exists CPUTAPID] } { + set _CPUTAPID $CPUTAPID +} else { + if { [using_jtag] } { + # See STM Document RM0316 + # Section 29.6.3 - corresponds to Cortex-M4 r0p1 + set _CPUTAPID 0x4ba00477 + } { + set _CPUTAPID 0x2ba01477 + } +} + +swj_newdap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID +dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu + +if {[using_jtag]} { + jtag newtap $_CHIPNAME bs -irlen 5 +} + +set _TARGETNAME $_CHIPNAME.cpu +target create $_TARGETNAME cortex_m -endian $_ENDIAN -dap $_CHIPNAME.dap + +$_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0 + +set _FLASHNAME $_CHIPNAME.flash +flash bank $_FLASHNAME stm32f1x 0 0 0 0 $_TARGETNAME + +reset_config srst_nogate + +if {![using_hla]} { + # if srst is not fitted use SYSRESETREQ to + # perform a soft reset + cortex_m reset_config sysresetreq +} + +proc stm32f3x_default_reset_start {} { + # Reset clock is HSI (8 MHz) + adapter speed 1000 +} + +proc stm32f3x_default_examine_end {} { + # Enable debug during low power modes (uses more power) + mmw 0xe0042004 0x00000007 0 ;# DBGMCU_CR |= DBG_STANDBY | DBG_STOP | DBG_SLEEP + + # Stop watchdog counters during halt + mmw 0xe0042008 0x00001800 0 ;# DBGMCU_APB1_FZ |= DBG_IWDG_STOP | DBG_WWDG_STOP +} + +proc stm32f3x_default_reset_init {} { + # Configure PLL to boost clock to HSI x 8 (64 MHz) + mww 0x40021004 0x00380400 ;# RCC_CFGR = PLLMUL[3:1] | PPRE1[2] + mmw 0x40021000 0x01000000 0 ;# RCC_CR |= PLLON + mww 0x40022000 0x00000012 ;# FLASH_ACR = PRFTBE | LATENCY[1] + sleep 10 ;# Wait for PLL to lock + mmw 0x40021004 0x00000002 0 ;# RCC_CFGR |= SW[1] + + # Boost JTAG frequency + adapter speed 140 +} + +# Default hooks +$_TARGETNAME configure -event examine-end { stm32f3x_default_examine_end } +$_TARGETNAME configure -event reset-start { stm32f3x_default_reset_start } +$_TARGETNAME configure -event reset-init { stm32f3x_default_reset_init } + +$_TARGETNAME configure -event trace-config { + # Set TRACE_IOEN; TRACE_MODE is set to async; when using sync + # change this value accordingly to configure trace pins + # assignment + mmw 0xe0042004 0x00000020 0 +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..e942cb2 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,19 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build_vn200", + "type": "shell", + "command": "make -C /home/stm32_devcontainer/${env:PROJECT_NAME_VN200}/build", // or any other build command + "args": [], + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": [ + "$gcc" + ], + "detail": "Generated task by Debugger." + } + ] +} \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..50ec221 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,79 @@ +FROM public.ecr.aws/lts/ubuntu:jammy as prerequisites + +ENV STM32CUBEIDE_VERSION=1.15.1 +ENV STM32CUBEMX_VERSION=1.15.1 +ENV STLINK_GDB_SERVER_VERSION=2.1.1 + +ENV TZ=Etc/UTC +ENV LICENSE_ALREADY_ACCEPTED=1 + +RUN apt-get update && \ + apt-get -y install \ + zip \ + libgtk-3-0 \ + cmake \ + net-tools \ + gdb-arm-none-eabi \ + gcc-arm-none-eabi \ + build-essential \ + git \ + libxtst6 \ + wget \ + ca-certificates \ + libncurses5 \ + openocd \ + pip && \ + pip install --upgrade pip && \ + rm -rf /var/lib/apt/lists/* + +# Install Chrome to be able to login to MyST +RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -O /tmp/google-chrome-stable_current_amd64.deb && \ + apt update && apt install -y /tmp/google-chrome-stable_current_amd64.deb + +#FROM prerequisites AS stm32_cubeide + +#COPY docker/en.st-stm32cubeide_1.15.1_21094_20240412_1041_amd64.sh.zip /tmp/stm32cubeide-installer.sh.zip + +# Install STM32 Cube IDE and delete installer +# RUN unzip -p /tmp/stm32cubeide-installer.sh.zip > /tmp/stm32cubeide-installer.sh && \ +# rm -rf /tmp/stm32cubeide-installer.sh.zip && \ +# chmod +x /tmp/stm32cubeide-installer.sh && \ +# echo "/opt/st/stm32cubeide_1.15.1\nqy\ny" | /tmp/stm32cubeide-installer.sh +#ENV PATH="${PATH}:/opt/st/stm32cubeide_${STM32CUBEIDE_VERSION}" + +FROM prerequisites AS stm32_cubemx + +# Install STM32 Cube MX +COPY docker/en.stm32cubemx-lin-v6-11-1.zip /tmp/stm32cubemx-installer.zip +COPY docker/auto-install.xml /tmp/auto-install.xml +RUN unzip /tmp/stm32cubemx-installer.zip -d /tmp/stm32cubemx-installer && \ + rm -rf /tmp/stm32cubemx-installer.zip && \ + chmod +x /tmp/stm32cubemx-installer/SetupSTM32CubeMX-6.11.1 && \ + /tmp/stm32cubemx-installer/SetupSTM32CubeMX-6.11.1 /tmp/auto-install.xml && \ + echo "alias stm32cubemx=/opt/st/stm32cubemx_6.11.1/STM32CubeMX" > ~/.bashrc + +FROM stm32_cubemx AS stlink_gdb_server + +# Install ST-Link GDB Server +COPY docker/en.st-link-server-v2-1-1.zip /tmp/st-link-server-installer.zip +RUN unzip /tmp/st-link-server-installer.zip -d /tmp/st-link-server-installer && \ + rm -rf /tmp/st-link-server-installer.zip && \ + apt install -y /tmp/st-link-server-installer/en.st-link-server_v2.1.1-2/st-stlink-server-2.1.1-1-linux-amd64.deb + +# Link the debugger correctly +RUN ln -s /usr/bin/gdb-multiarch /usr/bin/arm-none-eabi-gdb + +# Install firmware +RUN mkdir /root/STM32Cube && mkdir /root/STM32Cube/Repository + +COPY docker/stm32cube_fw_f4_1280.zip /tmp/stm32cube_fw_f4_1280.zip +RUN unzip /tmp/stm32cube_fw_f4_1280.zip -d /root/STM32Cube/Repository && \ + rm -rf /tmp/stm32cube_fw_f4_1280.zip + +COPY docker/STM32Cube_FW_F3_V1.11.4.zip /tmp/STM32Cube_FW_F3_V1.11.4.zip +RUN unzip /tmp/STM32Cube_FW_F3_V1.11.4.zip -d /root/STM32Cube/Repository && \ + rm -rf /tmp/STM32Cube_FW_F3_V1.11.4.zip + +RUN git config --global --add safe.directory /home/stm32_devcontainer + +ENTRYPOINT ["bash"] \ No newline at end of file diff --git a/docker/auto-install.xml b/docker/auto-install.xml new file mode 100644 index 0000000..b58463a --- /dev/null +++ b/docker/auto-install.xml @@ -0,0 +1,12 @@ + + + + + + + /opt/st/stm32cubemx_6.11.1 + + + + + diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml new file mode 100644 index 0000000..0de8e9c --- /dev/null +++ b/docker/docker-compose.yaml @@ -0,0 +1,30 @@ +services: + + stm32_devcontainer: + image: git.fasttube.de/fasttube/stm32_devcontainer:latest + pull_policy: never + container_name: stm32_devcontainer + stdin_open: true + tty: true + privileged: true + build: + context: ../ + dockerfile: docker/Dockerfile + volumes: + - type: bind + source: ../ + target: /home/stm32_devcontainer + - type: bind + source: /tmp/.X11-unix + target: /tmp/.X11-unix + - type: bind + source: /dev + target: /dev + network_mode: host + pid: "host" + ipc: "host" + environment: + DISPLAY: $DISPLAY + ROS_AUTOMATIC_DISCOVERY_RANGE: "LOCALHOST" + ROS_DOMAIN_ID: "0" + PROJECT_NAME_VN200: vn200 \ No newline at end of file diff --git a/docker/download.bash b/docker/download.bash new file mode 100755 index 0000000..b96ad6f --- /dev/null +++ b/docker/download.bash @@ -0,0 +1,3 @@ +wget https://cloud.fasttube.de/f/3245593 +wget https://cloud.fasttube.de/f/3245659 +wget https://cloud.fasttube.de/f/3245586 \ No newline at end of file