|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Fetch new code for an entire MCU series from an upstream STM repository. |
| 4 | + |
| 5 | +if [ $# -ne 2 ]; then |
| 6 | + echo "usage: $0 <mcu> <src>" |
| 7 | + echo "" |
| 8 | + echo "eg: $0 STM32WB path/to/STM32CubeWB" |
| 9 | + echo "where STM32CubeWB is from https://github.com/STMicroelectronics/STM32CubeWB.git" |
| 10 | + exit 1 |
| 11 | +fi |
| 12 | + |
| 13 | +mcu=$1 |
| 14 | +gitsrc=$2 |
| 15 | + |
| 16 | +cmsis=CMSIS/${mcu}xx |
| 17 | +hal=${mcu}xx_HAL_Driver |
| 18 | + |
| 19 | +if [ ! -d $cmsis ]; then |
| 20 | + echo "WARNING: $cmsis is not an existing directory, assuming a new MCU series" |
| 21 | + mkdir -p $cmsis |
| 22 | +fi |
| 23 | + |
| 24 | +if [ ! -d $hal ]; then |
| 25 | + echo "WARNING: $hal is not an existing directory, assuming a new MCU series" |
| 26 | + mkdir -p $hal |
| 27 | +fi |
| 28 | + |
| 29 | +# CMSIS: remove any old files and copy across the new ones. |
| 30 | +echo "Fetching CMSIS to $cmsis" |
| 31 | +rm -rf $cmsis/Include |
| 32 | +rm -rf $cmsis/Source |
| 33 | +cp -r $gitsrc/Drivers/CMSIS/Device/ST/${mcu}xx/Include $cmsis/ |
| 34 | +cp -r $gitsrc/Drivers/CMSIS/Device/ST/${mcu}xx/Source $cmsis/ |
| 35 | +rm -rf CMSIS/${mcu}xx/Source/Templates/*/linker |
| 36 | + |
| 37 | +# HAL: remove any old files and copy across the new ones. |
| 38 | +echo "Fetching HAL to $hal" |
| 39 | +rm -rf $hal/Inc |
| 40 | +rm -rf $hal/Src |
| 41 | +cp -r $gitsrc/Drivers/${mcu}xx_HAL_Driver/Inc $hal/ |
| 42 | +cp -r $gitsrc/Drivers/${mcu}xx_HAL_Driver/Src $hal/ |
| 43 | + |
| 44 | +for dir in $cmsis $hal; do |
| 45 | + # Process the new source code to: |
| 46 | + # - remove trailing white-space |
| 47 | + # - convert to unix line-endings |
| 48 | + # - expand tabs with 4 spaces |
| 49 | + # - convert non-ascii chars to ascii equivalent (should only be in comments) |
| 50 | + echo "Processing source code in $dir" |
| 51 | + for file in $(find $dir -name "*.[chs]"); do |
| 52 | + chmod 644 $file |
| 53 | + cat $file | awk "{sub(/[\t ]*$/,\"\")}1" | expand -t 4 | tr \\200\\205\\211\\221\\222\\223\\224\\226\\231\\244\\261\\265\\302\\327\\342 \'??\'\'\"\"\\-\'??u?x\' > tmp$$ |
| 54 | + /bin/mv tmp$$ $file |
| 55 | + done |
| 56 | +done |
| 57 | + |
0 commit comments