Skip to content

Commit

Permalink
Increase spread and range of internal-frequency variations
Browse files Browse the repository at this point in the history
Also renames the directrory files for oscillatory selection to sth like

  autobaud
  external_oscillator_x
  internal_oscillator_c-7.50%
  internal_oscillator_d-6.25%
  internal_oscillator_e-5.00%
  internal_oscillator_f-3.75%
  internal_oscillator_g-2.50%
  internal_oscillator_h-1.25%
  internal_oscillator_i
  internal_oscillator_j+1.25%
  internal_oscillator_k+2.50%
  internal_oscillator_l+3.75%
  internal_oscillator_m+5.00%
  internal_oscillator_n+6.25%
  internal_oscillator_o+7.50%
  • Loading branch information
stefanrueger committed Apr 10, 2023
1 parent 4e840b6 commit 0baa31b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ More detailed information here: [`make` options](https://github.com/stefanrueger
<p id="pre-compiled"></p>

**Pre-compiled bootloaders.** If compiling bootloaders is not feasible, feel free to try out one of
the 924,272 *different* pre-compiled bootloaders in the directory tree for [`MCU
the 1,066,518 *different* pre-compiled bootloaders in the directory tree for [`MCU
parts`](https://github.com/stefanrueger/urboot.hex/tree/main/mcus/). You can find bootloaders for
popular boards in a corresponding directory for
[boards](https://github.com/stefanrueger/urboot.hex/tree/main/boards/), for example, autobaud
Expand Down
9 changes: 8 additions & 1 deletion src/hexls
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ if(!$check) {
print("|:-:|:-:|:-:|:-:|:--|\n");
}
for my $line (@rows) {
$line->[4] = sprintf("[%s](%s/%s)", $line->[4], $md, $line->[4]) if defined($md) && $md ne "";
$line->[4] = sprintf("[%s](%s/%s)", $line->[4], forurl($md), forurl($line->[4])) if defined($md) && $md ne "";
printf("$l%d$c%d$c%s$c$t%s$t$c%s$l\n", @{$line});
}
if(defined($md) && @rows) {
Expand Down Expand Up @@ -401,3 +401,10 @@ sub getinteger {
return floor($n);
}
sub forurl {
local $_ = shift;
s/%/%25/g;
s/\+/%2B/g;
return $_;
}
29 changes: 17 additions & 12 deletions src/mkurboots
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ shopt -s extglob
# Maximum allowed UART/SWIO baud rate quantisation errors in ppm (22000 is 2.2%)
# External oscillators are relatively precise, can afford higher quantisation error
maxexterror=22000
maxinterror=4999
maxinterror=6000

run=1
mcu_bls=mcus
Expand Down Expand Up @@ -101,9 +101,9 @@ fcpus=(24000000 22118400 20000000 18432000 16000000 14745600 12000000 11059200 1
# Add internal Fcpus
setarray internalfcpu / "${intfcpus[$mcu]}"
for ifcpu in ${internalfcpu[@]}; do
# Adding +4 also generates b/l for Fcpu +/-1%, Fcpu +/- 2%, ... Fcpu +/- 4%
# Adding +7 also generates b/l for Fcpu +/-1.25%, Fcpu +/- 2.5%, ... Fcpu +/- 8.75%
if [[ $ifcpu -gt 30000 ]]; then
fcpus+=($ifcpu+4)
fcpus+=($ifcpu+7)
fi
done

Expand Down Expand Up @@ -278,25 +278,28 @@ autovar=; [[ /atmega103/at43usb320/at90s2313/at90s2333/at90s4433/at90s4414/at90s

####
# Set global variables based on $fbase/$df/$ftype/$b
# - fcpu ($fbase + df percent)
# - fcpu ($fbase + df*1.25 percent)
# - fbfilenm (autobaud or sth like j8m0_57k6)
# - fbgitdir (path element for sorted display in git, eg, internal_oscillator+1%/+8m000000_hz/++57k2_baud)
# - fbcomdir (path element for machine readability, eg, internal_oscillator/8080000_hz/57200_baud)
# - fbgitdir (path element for sorted display in git, eg, internal_oscillator_j+1.25%/+8m000000_hz/++57k2_baud)
# - fbcomdir (path element for machine readability, eg, internal_oscillator/8100000_hz/57200_baud)

mkfbvars() {
local fbase=$1
local df=$2
local ftype=$3
local b=$4

fcpu=$(($fbase + $df*$fbase/100))
fcpu=$(($fbase + $df*125*$fbase/10000))

local fchr=
local fpercent=
local ftypedir=
if [[ $ftype == i ]]; then
fchr=${alphabet[$((8+$df))]}
[[ $df -ne 0 ]] && fpercent=$(printf "%+d%%" $df)
if [[ $df -ne 0 ]]; then
xp=$(($df*125)); xp=${xp::-2}.${xp: -2}
fpercent=$(printf "%+3.2f%%" $xp)
fi
ftypedir=internal_oscillator
elif [[ $ftype == x ]]; then
fchr=x
Expand Down Expand Up @@ -326,7 +329,7 @@ mkfbvars() {
fbcomdir=autobaud
else
fbfilenm=$fchr${fcpunm}_$baudnm
fbgitdir=$ftypedir$fpercent/${fcpudirnm}_hz/${bauddirnm}_baud
fbgitdir=${ftypedir}_$fchr$fpercent/${fcpudirnm}_hz/${bauddirnm}_baud
fbcomdir=$ftypedir/${fcpu}_hz/${b}_baud
fi
}
Expand Down Expand Up @@ -411,7 +414,7 @@ for fc in ${fcpus[@]}; do
fbase=16000000
ndf=0
elif [[ $fc == *+[0-8] ]]; then
# 9600000+4 means loop F_cpu from F_cpu-4% to F_cpu+4%
# 9600000+7 means loop F_cpu from F_cpu-8.75% to F_cpu+8.75%
ftype=i
fbase=${fc%??}
ndf=${fc: -1}
Expand All @@ -429,8 +432,10 @@ for fc in ${fcpus[@]}; do
continue
fi

# Ensure br < Fcpu/100 for all internal oscillator Fcpu variations
if [[ $ftype == i && $b -ge $(($fbase*(1-$ndf/100)/100)) ]]; then
# Ensure SWIO quantisation error can be under maxinterr ppm, ie, 0.5/cycles < maxinterr ppm.
# Using cycles = fcpu/br requires that for all internal oscillator Fcpu variations must hold
# br < Fcpu*maxinterror/500000
if [[ $ftype == i && $b -ge $((($fbase-$ndf*125*$fbase/10000)*$maxinterror/500000)) ]]; then
continue
fi

Expand Down

0 comments on commit 0baa31b

Please sign in to comment.