Skip to content

BLDC.cyacd static analysis (Bebop 2 4.7.1 vs Bebop 1 4.0.6)

Static analysis only. Nothing was flashed, executed or touched. Labels: EVIDENCE means flat-image address plus bytes/disassembly; INFERENCE is my reading; UNKNOWN means not determined. All addresses are absolute flash/code addresses (flat image base 0, so file offset = address). “B2” = Bebop 2 image, “B1” = Bebop 1 image.

Tooling note: the mcghidra docker container could not see the scratchpad (it failed with “Binary not found: /binaries/b2.bin”; I stopped it, docker_status now shows no containers). I used host Ghidra 12.1.2 headless (language 8051:BE:16:default, BinaryLoader base 0, script w/scripts/Dump.java) and radare2 -a 8051 instead. Ghidra’s decompile of 8051/Keil code mangles carry-flag idioms, so every claim below that matters was re-checked against disassembly.

Conversion script (also saved as cyacd2bin.py)

Section titled “Conversion script (also saved as cyacd2bin.py)”
import sys
def conv(src,dst):
rows={}
lines=open(src).read().split()
print(src,'header',lines[0])
for l in lines[1:]:
b=bytes.fromhex(l[1:])
arr=b[0];row=(b[1]<<8)|b[2];ln=(b[3]<<8)|b[4];d=b[5:5+ln]
assert (sum(b)&0xff)==0
rows[(arr,row)]=d
print('arrays',sorted({a for a,_ in rows}),'rows',min(r for _,r in rows),max(r for _,r in rows),len(rows))
r=sorted(rows); prev=None
for a,rw in r:
if prev is not None and rw!=prev+1: print('gap/jump', prev,'->',rw,'array',a)
prev=rw
hi=max(rw for a,rw in rows)
img=bytearray(b'\xff'*((hi+1)*256))
for (a,rw),d in rows.items(): img[rw*256:rw*256+len(d)]=d
open(dst,'wb').write(img)
base='firmware/extracted/'
conv(base+'bebop-2-4.7.1/rootfs/lib/firmware/BLDC.cyacd','b2.bin')
conv(base+'bebop-1-4.0.6/rootfs/lib/firmware/BLDC.cyacd','b1.bin')

Output: B2 array 0, rows 25..112 contiguous (88 rows) plus row 127 (metadata), jump 112 -> 127. B1 array 0, rows 24..108 (85 rows) plus row 127, jump 108 -> 127. Both flat images are 32768 bytes. Row padding inside application rows is 0x00, gaps are 0xFF.

CPU: 8051 core, EVIDENCE. The application begins with Keil C51 runtime code: B2 0x1911 is 78 ff e4 f6 d8 fd 02 3f 25 = mov r0,#0xff; clr a; mov @r0,a; djnz r0; ljmp 0x3f25 (idata clear then startup), 0x3f34..0x3f5a are the C51 movc a,@a+dptr init-table copy loops, and code uses movx to PSoC 3 register addresses: I2C FF block 0x49ca/0x49d6..0x49d8, SPC 0x4720/0x4722, UDB working registers 0x6401/0x6462/0x646b/0x646f, GPIO 0x5120/0x51c0, EEPROM window 0x8000..0x800f. INFERENCE: PSoC 3 (consistent with silicon id 0x1E068069 in the cyacd header, I did not map the id to a part number).

Bootloader versus application. The cyacd contains only application rows plus the metadata row. Application start: B2 0x1900 (row 0x19), B1 0x1800 (row 0x18). The bootloader itself is not in the file; it lives below the application start. EVIDENCE for the metadata (row 127, bytes at 0x7FC0):

B2 0x7fc0: 8d 00 00 3e f3 00 00 00 18 00 00 58 00 00 00 00 ... 0x7fd2: 01 01
B1 0x7fc0: ae 00 00 3b 88 00 00 00 17 00 00 55 00 00 00 00 ... 0x7fd2: 01 01

My decode (checked where noted): byte 0 is the application checksum, verified: the 8-bit two’s complement of the byte sum of rows 25..112 is 0x8d (B2) and of rows 24..108 is 0xae (B1), matching exactly. Bytes 1..4 are a 32-bit big-endian entry address, 0x00003EF3 (B2) and 0x00003B88 (B1). INFERENCE: this is the application’s startup vector; the first 3 bytes of each image are 02 3e f3 / 02 3b 88 (an LJMP to the same value). Bytes 5..8 are 0x18 / 0x17, which is the last bootloader row (INFERENCE from Cypress metadata layout, and it equals first application row minus 1). Bytes 9..12 are 0x5800 / 0x5500 bytes, equal to 88 / 85 rows x 256 (checked). The application therefore spans 0x1900..0x70FF (B2) and 0x1800..0x6CFF (B1), but real code ends around 0x5DDF in B2; everything after is PSoC config/UDB data tables and accessor stubs (0x5da2 mov dptr,#0x6462; movx a,@dptr; mov r7,a; ret and similar).

Version bytes from get_info, EVIDENCE (the handler builds the 14-byte reply in idata 0x45..):

B2 0x220c: 78 45 76 06 08 76 07 08 76 52 08 76 04 mov r0,#0x45; mov @r0,#6; inc r0; mov @r0,#7; ... #0x52 ('R'); ... #4
B1 0x2161: 78 45 76 06 08 76 03 08 76 52 08 76 04

So B2 reports 6.7.R.4 and B1 reports 6.3.R.4 (major, minor, letter ‘R’, 4 motors). No ASCII version or build strings exist in either image (I searched; only noise). The remaining reply bytes: r4..r7 come from xdata 0x9a..0x9d, r8..r11 from xdata 0x9e..0xa1, r12 from xdata 0xa2 (last error). r13 is not written by the get_info handler (INFERENCE: stale byte, in practice the temperature byte of the previous 0x20 reply at idata 0x52).

I2C address, EVIDENCE: lcall 0x5c88 with r7=8 at init (0x5c88: mov a,r7; anl a,#0x7f; mov dptr,#0x49ca; movx @dptr,a), so the I2C FF address register is written with 8. The slave buffers are initialised at 0x5399 with sizes 0x20: read buffer idata 0x45, write buffer idata 0x65 (call args 50b5(0x45,0,0,0x20) and 513b(0x65,0,0,0x20), buffer roles INFERENCE from use below).

What differs between B1 and B2 beyond relocation: see section 7 (ramp, temperature window, battery window, minimum speed, timing constants). The command set, state machine and error numbering are structurally the same.

Mechanism, EVIDENCE: the I2C ISR is at 0x2b31 (starts c0 e0 c0 f0 c0 83 c0 82). When the FF block reports a stop after a write (state byte xdata 0x1fc == 0x11) it calls lcall 0x1fb5 (0x2bac). 0x1fb5 loads the command byte from idata 0x65 (mov r0,#0x65; mov a,@r0) and calls the Keil case helper 0x1efe, which pops the return address as a table pointer, matches the byte against 3-byte entries [addr_hi][addr_lo][value], and jmp @a+dptrs to the match, or to the default after a 00 00 terminator. Table at 0x1fc4 (B2):

0x1fc4: 1f e6 02 | 20 88 20 | 21 9c 40 | 21 88 4d | 21 b7 60 | 21 d3 80 | 22 b4 82 | 23 86 8d | 22 00 a0 | 22 96 fa | 00 00 | 23 a2 (default)
Cmd Handler B2 What it does (EVIDENCE from disassembly)
0x02 set_ref_speed 0x1fe6 XORs idata 0x65..0x6e into idata 0x6f (mov 0x43,#0x0a loop at 0x1fe6..0x1ffa); nonzero means checksum mismatch, clr 0x20.5, frame dropped. Then requires state xdata[0] == 3 or 4 (0x200b..0x2016), else dropped. Then per motor reads u16 BE from idata 0x66+2k and clamps to [0x05DC, 0x3A98] = [1500, 15000] (0x2041..0x2062), stores to xdata 0x2a+2k
0x20 get_obs_speed 0x2088 builds reply in idata 0x45.., see below
0x40 start 0x219c if errno(xdata 2)==0 && state(xdata 0)==1 { xdata[3]=0; xdata[0x98]=0 }; the start-direction byte is ignored
0x4d gpio 0x2188 `xdata[0x51c0] = (xdata[0x51c0] & 0xfe)
0x60 stop 0x21b7 if state in [2,4] { xdata[3]=1 } (stop request)
0x80 clear_error 0x21d3 if errno is not 10 or 11 and state != 6: errno=0, MotFault byte (xdata 0x89)=0, xdata[3]=1, xdata[0x98]=0
0x82 play_sound 0x22b4 only if state==1 (idle); with a 2-byte frame stores the signed sound number into xdata 0x98 (accepted when |n|<4); with a 6-byte frame it fills a per-motor 4x2 byte array at 0xb5 (note data, details UNKNOWN)
0x8d set_i2c_timeout 0x2386 copies the u16 BE argument (idata 0x66,0x67) into register bank 1: idata 0x08:0x09 (countdown) and 0x0a:0x0b (reload). No range check
0xa0 get_info 0x2200 builds 13 bytes at idata 0x45..0x51 (see section 1)
0xfa clear_EEPROM 0x2296 zeroes xdata 0x9a..0xa2 (flight count, flight times, last error) and sets xdata 0xa8=1, which makes the idle loop rewrite the EEPROM statistics block; it does not touch any parameters

Missing commands, EVIDENCE: 0x06 reverse, 0x2b get_assert, 0xc0 settings and 0xe0 log page are NOT in this table in either image, and idata 0x65 (command byte) is referenced nowhere else (grep of all mov r0,#0x65 / mov r1,#0x65 and the Ghidra xrefs: only 0x1fbe, 0x1ff0 and 0x53a8 which is the buffer init). An unknown byte goes to the default 0x23a2, which does clr 0x20.5 and then the common epilogue. B1 has the identical ten-command table at 0x1ed4: 02->1ef8, 20->1f9a, 40->20e4, 4d->20aa, 60->20ff, 80->211b, 82->2207, 8d->2216, a0->2155, fa->21ea, default 2232. INFERENCE: the host tool’s settings, log and reverse paths target a different firmware family (or are dead against this one); a host sending 0xC0/0xE0/0x06/0x2B to this firmware gets no action (it will be treated as “unknown command”).

Frame lengths and XOR8, both ends.

Host to PSoC (cmd 0x02): the firmware does not check the byte count. It XORs a fixed 10 bytes (idata 0x65..0x6e) and expects the check byte at the 11th (0x6f), i.e. exactly the 4-motor frame [02] 4x(hi,lo) [00] [xor] = 11 bytes. EVIDENCE: 0x1fe6 75 43 0a (count 10), XOR loop 78 6f e6 67 f6 ([0x6f] ^= [0x65+i]). This agrees with the host (XOR over command, motor bytes and the zero pad).

PSoC to host (cmd 0x20): reply built at idata 0x45..0x53, EVIDENCE from 0x20a1..0x2186: for n=4, bytes 0..7 are four motor words (byte0 = high byte of xdata[0x42+2k] with bit 7 set from flag xdata[0x8b+k], byte1 = xdata[0x43+2k]); bytes 8,9 = xdata[8],[9] (battery, millivolts, see below); byte 10 = xdata[1]+xdata[0] (status: low nibble current state in xdata 0, high nibble = state at time of error in xdata 1); byte 11 = xdata[2] (errno); byte 12 = xdata[0x89] (MotFault); byte 13 = xdata[0x99] (signed temperature, degrees C); byte 14 = XOR of bytes 0..13: the loop at 0x216a..0x2186 does [0x53] ^= [0x45+i] for i=13..0, destination index = 4*r5+6 = 14. Total 15 bytes = 2n+7, exactly the host’s expectation. Extra: if the host sends a 2-byte command [20][x] (rx count 2) the firmware uses a 3-byte-per-motor layout (adds the low byte of the duty xdata[0x81+2k]) and a 19-byte reply; the stock host never does this.

Battery word, EVIDENCE: 0x4991 reads the ADC (xdata 4:5), calls 0x56f5 which computes signed16 * 0x00044A20 / 0x00016000 (281120/90112 = 3.1197 per count) and stores the result as xdata[8:9]; separately the same value divided by 100 (0x1c35) goes to xdata[7] (decivolts). The 0x20 reply carries xdata[8:9], so it is in the same unit the host divides by 100 to get 0.1 V steps. The 3.1197 factor per ADC count has no obvious unit (INFERENCE: millivolts per count).

3. Status and errno enumerations, and what raises them

Section titled “3. Status and errno enumerations, and what raises them”

State byte xdata[0], EVIDENCE of writes: 0 init (0x4be9), 1 idle (0x4651), 2 ramp (0x23b5, mov r0,#0; mov a,#2; movx @r0,a at 0x23d4..0x23d8), 4 closed loop (0x4a47), 5 stopping (0x386e), 6 suicided (0x5765). State 3 (“opened loop spinning”) is never written anywhere in the B2 image (grep of all stores to xdata 0 shows 2,5,1,4,0,6 only), so only closed-loop control exists; set_ref_speed’s “state 3 or 4” test is only ever satisfied in state 4.

Main loop, EVIDENCE (0x56d8): 4be9() init; then forever { 4651() idle/wait-for-start; 23b5() ramp; if (errno==0 && xdata[3]!=1) 4a47() closed loop; 386e() stop }.

Raise rule, EVIDENCE (0x5712 and 0x572e): an error is recorded only if the new errno is greater than the current one (if (errno < new)); it sets xdata[1]=state<<4, xdata[0x98]=0xfe (error sound pattern) and errno=new. It does NOT set the stop request xdata[3]. So errno behaves as a priority latch: a lower-numbered error can never replace a higher one.

errno (host name) Raised by (EVIDENCE)
1 EEPROM access failure 0x3991 at power-up when the 9-byte stats block at EEPROM 0x8000..0x8008 does not sum to the checksum byte at 0x8009 (572e(1) at 0x3a82); 0x3745 when 5 attempts to write the stats block fail (572e(1) at 0x385d)
2 Motor stalled or low speed ISR 0x3aa3: if UDB status 0x646b == 0 and monitor flag xdata[0x8f] != 0, bits in UDB status 0x646f (one per motor) cause errno 2 when state != 5 (INFERENCE: those bits are per-motor commutation/zero-crossing timeouts; the bit meaning itself is UNKNOWN)
3 Shock on propeller 0x26c4 per-motor speed estimate: if the filtered speed value (xdata 0x42+2k source) is >= 0x3E80 = 16000 on 128 consecutive passes, errno 3 (28b4..28e0: subb #0x80 / subb #0x3e, counter at xdata 0x90+k compared with 0x80, mov r7,#3; lcall 0x5712). Needs state 3 or 4. It is effectively an overspeed check, name mismatch is mine to flag
4 I2C timeout 0x541f, section 6
5 H-bridge fault same ISR 0x3aa3: if UDB status 0x646b != 0 outside state 0/5, errno 5 (state 0 gives errno 0x0b instead)
6 Battery shut-down unexpectedly 0x577f at init: reads EEPROM byte at 0x800f (0x59d3); if it is 0xFF, errno 6 (78 a2 74 06 f2 ...). INFERENCE: a “clean shutdown” flag; what writes it is UNKNOWN
7 Incorrect motor setting value never raised in B2 (no settings, see below)
8 BLDC temperature out of bounds 0x46ca, section 4
9 Battery voltage out of bounds 0x4991 each tick: pack voltage in decivolts v (xdata 7) must satisfy 0x58 <= v < 0x87 (88..134, i.e. 8.8 V to 13.4 V, setb c; subb #0x57 at 0x49aa and subb #0x87 at 0x49b0); a saturating counter xdata[0x94:0x95] starts at 0x0080 (0x4066), increments toward 0x80 while good, decrements while bad, and errno 9 is raised when it is 0 (about 129 consecutive bad ticks). 4a47 clears errno 9 again when the counter is back to >= 0x40 (0x4a61..0x4a73). Also at init 0x51e0: v <= 87 gives errno 9
10 Incorrect number of LIPO cells 0x51e0 at init: cells = ceil(v/45) (loop mul 0x2d); anything other than 3 (so only 91..135 decivolts accepted) gives 5712(cells,10) and MotFault byte = cell count (matches host print)
11 Defective H-bridge/broken phases at selftest 0x3203 at init (per-motor phase measurement; any motor outside tolerance gives 5712(mask,0x0b) at 0x3361) and ISR 0x3aa3 when UDB 0x646b != 0 in state 0
12 Motor firmware flash update failed never raised in B2 (no write site found)
13 Code assertion failed never raised in B2 (no write site found); consistent with no 0x2b handler

Completeness of the search, EVIDENCE: all lcall 0x5712 are at 0x28e0, 0x3361, 0x51fe; all lcall 0x572e are at 0x385d, 0x3a82, 0x4711, 0x49d7, 0x5211, 0x5430, 0x5790; direct errno writes are only in ISR 0x3aa3, the clear paths, init and 0x572e/0x5712 themselves.

Init consequences, EVIDENCE (0x4be9..): after init, if errno == 5 or errno >= 10, 5765 sets state 6 and loops forever (never leaves). 0x80 clear_error refuses errno 10 and 11 and refuses state 6, so those need a power cycle.

Defaults of the 45 settings: NOT PRESENT as a table. UNKNOWN as a settings table, because the firmware has no 0xC0 handler and no 45-entry table (I searched the data tail 0x5de3..0x7011 and the code for any parameter array; the only EEPROM data read at boot is the 10-byte stats block 0x8000..0x8009 and the flag at 0x800f). The values below are the hard-coded constants that correspond to the host’s setting names, B2 first:

Host setting Hard-coded equivalent in B2 Evidence
LIPO number of cells 3, fixed by code 0x51f5 xrl a,#3
Min/Max LIPO cell voltage no per-cell value; pack window 88..134 decivolts (8.8..13.4 V) in the run-time check, 91..135 accepted for the 3-cell test 0x49aa..0x49b2, 0x51e3
Speed units/gears/poles no parameters; speed value to timer period is 60,000,000 / (6 * value) (0x4fc0: 1f48 then 1dab with dividend 0x03938700), and the inverse in 0x4da7. INFERENCE: with a 1 MHz timer this is electrical RPM, timer clock UNKNOWN 0x4fc0..0x4fe9
Minimal speed reference clamp low 1500 0x2041..0x204f
Rated/max speed reference clamp high 15000 0x2054..0x2062
Max propeller acceleration reference slew limit +/-500 per loop tick: 0x3e28 clamps the change to 0xFE0C / 0x01F4 0x3e28 (bVar5=0xfe,bVar4=0xc / 1,0xf4)
Threshold satured PWM duty clamp [0x10, 0xFF]; saturated flag when duty >= 0xFA 0x4b9c..0x4bd5
Speed PID integral saturation +/-100000 (0x000186A0) 0x3103..0x3145
Other PID gains, feedforward, scaler UNKNOWN (constants such as 0x190 and 0x9001 appear but I did not derive the formula) 0x307c
Security timeout I2C lost 1024 loop ticks (0x0400), see section 6 0x53b7
Max overspeed errors 128 passes at >= 16000 0x28b4..
Max low Vbat errors counter 128 0x4066, 0x49b5..
Die min/max temperature -10 and +95 degrees C section 4
Alignment, ramp section 6 0x23b5..
PWM frequency, complementary, push/pull, motor timing, ADC max voltage, Vbat resistors, BEMF RC filter UNKNOWN (lives in the PSoC config/UDB tables or hardware, not decoded)

EVIDENCE, 0x46ca (called once per 1000 ticks from the tick routine 0x4dee, in every state). It reads the die temperature through the SPC (0x43a4, SPC registers 0x4720/0x4722; the “SPC” attribution is INFERENCE, the register addresses are EVIDENCE) into idata 0x25:0x26 and stores the low byte as signed degrees C in xdata[0x99] (the byte the host shows as Temp):

0x46fd: 78 99 e2 ff c3 64 80 94 df 50 07 u = temp ^ 0x80; if u >= 0xdf -> error
0x4708: ef 64 80 94 76 50 07 if u < 0x76 -> error (else OK at 0x4716)
0x470f: 7f 08 12 57 2e mov r7,#8; lcall 0x572e (errno 8)

With u = temp + 128: errno 8 is raised when temp >= 95 C or temp < -10 C (B2). Action: errno 8, error sound pattern (xdata 0x98 = 0xfe), and nothing else. It does not set the stop request, and errno 8 is not in the 2..5 range that makes the closed-loop exit (see section 6), so the motors keep running. Clearing: when errno == 8 and the next once-per-second sample is inside the window the code clears errno (4716..4733; the second compare pair at 0x4723..0x472d is always true once u >= 0x76 so there is no hysteresis in practice, ordinary reading of the disassembly). While errno is 8 a new start is refused (0x40 needs errno 0). B1 window is -20 C .. 80 C (subb #0xd0, subb #0x6c at 0x41d6/0x41dd).

EVIDENCE: the main loops are paced by 0x4dee at the end of each iteration: it spins on UDB status register 0x6462 bit 0 (0x5da2: mov dptr,#0x6462; movx a,@dptr) then writes 0xF9 to UDB register 0x6401 (0x5db4: mov dptr,#0x6401, value 74 f9/7f f9 at 0x4e2c). INFERENCE: a UDB timer reloaded with 249 each tick (250 counts); the clock feeding it is UNKNOWN, so I cannot derive the tick period from constants. The tick routine also counts down a 16-bit counter from 0x03E8 = 1000 (xdata 0xa4:0xa5, 0x4dee: stores 3 and 0xE8) and increments the seconds-of-flight counter xdata 0xa6:0xa7 each time it reaches zero, which the end-of-flight routine (0x4c34, called from the stop path 0x386e) adds into the total flight time reported in seconds. INFERENCE: one tick is 1 ms. That agrees with the host’s “cycles x 1 ms” label and with 250 counts at a 250 kHz clock, but no clock constant in the image proves it. Speed loop: one PID update per closed-loop iteration (0x4a47 loop: 0x26c4 measure, 0x3e28 slew/PID, 0x49ef apply duties, 0x4dee tick), so the speed-loop period equals the tick period. PWM carrier period: UNKNOWN. B1 has the same 0xF9 reload (0x49e1).

6. Ramp, soft start, and loss of I2C commands

Section titled “6. Ramp, soft start, and loss of I2C commands”

Ramp / soft start, B2, EVIDENCE from 0x23b5..0x2685 (all durations in loop ticks, 1 ms each by INFERENCE above):

Start: only when xdata[3]==0 (set by 0x40) and errno==0. Setup at 0x23c9: base 0x2f, end speed 0x09C4 = 2500, all four motor targets (xdata 0x2a, 0x32) set to 2500 and duty (xdata 0x80) to 0x002f = 47.

Phase 0, alignment: voltage demand steps from 1 to 0x15 (21), one step per 10 ticks (subb #0x0a at 0x246d, xrl a,#0x15 at 0x247f), so about 200 ticks. Duty = demand * 0x6f / Vbat(decivolts) (0x2685.., mov a,#0x6f-style multiply by 111 then divide by xdata[7], with Vbat floored at 0x57), INFERENCE for the unit of demand (decivolts).

Phase 1, ramp: lasts 0x0258 = 600 ticks (subb #0x58 / subb #0x02 at 0x25e1..0x25ee). Demand stays at 47 (the term (1af-0x2f)*t/600 is zero because xdata 0x1af is 0x2f and never changed). Speed value A(t) = 167 + 2333 * t^2 / 600^2, i.e. quadratic from 167 (0xa7) to 2500, converted with the 0x4fc0 speed-to-period formula into the commutation timer (0x2507..0x25de). Units of A: UNKNOWN (propeller RPM versus electrical, depends on the unknown timer clock).

Phase 2, lock: 200 ticks (0x2612..: cmp 200 via (1a9<200), result returns to the main loop), holding speed 2500 and duty 47; at 100 ticks into it the stall/fault monitor flag xdata 0x8f is set to 1 (this arms errno 2 detection in ISR 0x3aa3).

Total spin-up about 200 + 600 + 200 = 1000 ticks (INFERENCE 1.0 s), then closed loop with the reference at 2500 until the first accepted set_ref_speed. Aborts: errno in 2..5 or xdata[3]!=0 returns from the ramp at any time (0x244a..0x245f). set_ref_speed is silently ignored during the ramp (state 2). The I2C watchdog is NOT evaluated during the ramp.

Stop sequence, EVIDENCE 0x386e (state 5): duty of all motors is set to the average of the four duties and then reduced by 1 count per tick until it reaches 0 (so ramp-down takes about “duty” ticks, at most 255), then all PWM are zeroed and a 300 tick (0x012C) coast with measurement runs, then the code returns to idle (state 1) and saves the flight stats (0x3745).

Loss of I2C commands, EVIDENCE:

Mechanism. Register bank 1: idata 0x0a:0x0b = reload value, 0x08:0x09 = countdown. Power-up default (0x53b7: 75 0a 04 75 0b 00 85 0a 08 85 0b 09 c2 04) sets both to 0x0400 = 1024. Any valid command handler ends with bit 0x20.4 = bit 0x20.5 (“activity” flag). The watchdog routine 0x541f, called once per closed-loop iteration only:

541f: mov a,0x0b; orl a,0x0a; jz ret ; reload == 0 -> watchdog disabled
5425: jb 0x20.4,543d ; activity since last tick -> reload
5428: mov a,0x09; orl a,0x08; jnz 5434 ; countdown != 0 -> decrement
542e: mov r7,#4; lcall 0x572e ; countdown == 0 -> errno 4
543d: mov 0x08,0x0a; mov 0x09,0x0b; clr 0x20.4

So by default the firmware raises errno 4 after about 1025 consecutive closed-loop iterations with no valid command, about 1.0 s if one tick is 1 ms (INFERENCE for the time). The value is host-writable with cmd 0x8d (u16 loop ticks, unchecked), and 0 disables the watchdog entirely.

Reaction. errno 4 makes the closed-loop loop exit (0x4a47 exits when errno is in 2..5 or xdata[3]!=0, subb #2 / subb #5 at 0x4a54..0x4a5c and 0x4a85..0x4a8d), then main calls the stop routine 0x386e described above: motors ramp down and coast, state returns to idle with errno 4 latched and the error sound active. A restart needs 0x80 clear_error then 0x40 start.

Safety-relevant findings (each is EVIDENCE for the code, the consequences are mine):

  1. The watchdog counts any valid command as activity, including the read-only polls get_obs_speed (0x20) and get_info (0xa0), not just set_ref_speed. A host that keeps polling status but stops sending speeds keeps the motors at the last reference indefinitely.
  2. It is enforced only in state 4 (closed loop). It is not evaluated during ramp, lock or stopping.
  3. Because of the raise rule (new errno must exceed the current one), if errno is already 6, 8 or 9 (>4) when the timeout expires, 572e(4) does nothing, and since errno 6, 8, 9 are outside 2..5 the loop does not exit: motors keep running with no I2C supervision until that errno clears (errno 9 clears itself when the battery counter recovers, errno 8 clears at the next in-window temperature sample). Over-temperature or low-battery therefore disable the I2C-loss protection while they last.
  4. Over-temperature (8) and battery (9) never stop the motors in this image, see section 4; only errors 2..5 and a stop request (0x60, or ISR-set xdata[3]=1) do.
  5. An unrecognised or checksum-failed frame clears the activity flag (0x20.4 gets 0x20.5 = 0 at 0x23a2/0x23a4) even if a valid command arrived earlier in the same tick.
  6. There is no separate hardware watchdog reset path that I found; I did not exhaustively check PSoC watchdog/CTW registers (UNKNOWN).

Same structure, relocated (B2 code is shifted by 0xEE..0x100 against B1 at most addresses). Identical ten-command table and state/errno structure (B1 0x5288 main loop is the same four-call sequence). I2C timeout default is the same 0x0400 (B1 0x4fb7). Differences found, EVIDENCE by disassembly:

Item B1 (4.0.6, fw 6.3.R.4) B2 (4.7.1, fw 6.7.R.4)
Application range, rows 0x1800..0x6CFF, rows 24..108 (85) 0x1900..0x70FF, rows 25..112 (88)
Entry per metadata 0x3B88 0x3EF3
Reference clamp 3000 (0x0BB8) .. 15000 1500 (0x05DC) .. 15000
Temperature window -20 C .. 80 C (0x41d6 d0, 0x41dd 6c) -10 C .. 95 C
Battery window (decivolts) 91 .. 128 (subb #0x5a, subb #0x81 at 0x4549/0x454e) 88 .. 134
Ramp base duty / demand 0x33 = 51 0x2f = 47
Ramp end speed 0x0BB8 = 3000 0x09C4 = 2500
Ramp start speed term 0x1e = 30 0xa7 = 167
Ramp duration 0x0190 = 400 ticks 0x0258 = 600 ticks
Alignment 4 ticks/step, 0x33 = 51 steps 10 ticks/step, 0x15 = 21 steps
Lock phase 0x32 = 50 ticks, monitor armed at 0x19 = 25 200 ticks, armed at 100
Duty scale factor / Vbat floor 0x6d = 109 / 0x5a = 90 0x6f = 111 / 0x57 = 87
PID integral clamp 0x000186A0 pattern not found at the same form present at 0x3103

I did not diff the PID, EEPROM-stats and PSoC config code between the images, so other tuning differences may exist.

  1. What clock drives the UDB tick timer (reload 249)? Decoding the UDB/clock config tables in 0x5ec2..0x7011 would give the real tick, ramp and watchdog durations. Everything in “ticks” here is milliseconds only by inference.
  2. Units of the speed value (electrical vs propeller RPM, depends on timer clock and the gear/pole numbers that are not in the image).
  3. Meaning of UDB status bits 0x646b/0x646f (fault/stall) and PWM frequency/complementary/timing settings.
  4. What sets EEPROM byte 0x800f (errno 6 source).
  5. Whether the host tool’s 0xC0/0xE0/0x06/0x2B commands exist in any other firmware revision, and whether Bebop 2 hardware ever runs a different BLDC image than this cyacd (the cyacd shipped in 4.7.1 has none of them).
  6. PID gains and feedforward formula in 0x307c; the 0x82 6-byte (sound/note) payload; the effect of get_obs_speed’s 2-byte variant.
  7. Does the flight controller side rely on the watchdog, and with what value does it call 0x8d (the host default in the decompile notes should be compared with 1024)?

Comments

Spotted a mistake, or tried this on your own Bebop? Leave a note. Comments are kept on this site's own server.