Unable to program SAM4S on Husky: timeout

Running the “1-Connecting to Hardware” notebook with an CW Husky, all fine except programming is failing with a timeout when running cw.program_target(scope, cw.programmers.SAM4SProgrammer, "../firmware/mcu/simpleserial-base/simpleserial-base-CWHUSKY.hex")

Running off the latest CW 6.0.0 dev branch on a Linux fresh install of Ubuntu 22. What am I missing here?

Error trace below:


OSError Traceback (most recent call last)
Cell In[20], line 4
1 #cw.program_target(scope, cw.programmers.XMEGAProgrammer, “path/to/firmware.hex”)
2 #cw.program_target(scope, cw.programmers.STM32FProgrammer, “path/to/firmware.hex”)
3 #cw.program_target(scope, cw.programmers.AVRProgrammer, “path/to/firmware.hex”)
----> 4 cw.program_target(scope, cw.programmers.SAM4SProgrammer, “…/firmware/mcu/simpleserial-base/simpleserial-base-CWHUSKY.hex”)

File ~/chipwhisperer/software/chipwhisperer/init.py:181, in program_target(scope, prog_type, fw_path, **kwargs)
179 prog._logging = None
180 prog.open()
→ 181 prog.find()
182 prog.erase()
183 prog.program(fw_path, memtype=“flash”, verify=True)

File ~/chipwhisperer/software/chipwhisperer/capture/api/programmers.py:129, in save_and_restore_pins..func_wrapper(self, *args, **kwargs)
126 target_logger.debug(‘Changing {} pin configuration’.format(pin_setup))
128 try:
→ 129 val = func(self, *args, **kwargs)
130 finally:
131 target_logger.debug(‘Restoring {} pin configuration’.format(pin_setup))

File ~/chipwhisperer/software/chipwhisperer/capture/api/programmers.py:185, in SAM4SProgrammer.find(self, power_cycle)
183 prog = self.get_prog()
184 target_logger.info(“Connecting to SAMBA”)
→ 185 prog.con(self.scope)
186 target_logger.info(“Done!”)

File ~/chipwhisperer/software/chipwhisperer/hardware/naeusb/bootloader_sam3u.py:250, in Samba.con(self, port, usbmode)
247 res = ser.read(2)
248 # print(res)
→ 250 cid = self.chip_id()
252 target_logger.info(‘FWUP: CID = %04x’ % cid)
254 #Originally this was used to limit to SAM3U
255 #eproc = (cid >> 5) & 0x7
256 #arch = (cid >> 20) & 0xff
257 #if eproc == 3 and ((0x80 <= arch <= 0x8a) or (0x93 <= arch <= 0x9a)):
258 # target_logger.info(‘FWUP: Detected SAM3’)

File ~/chipwhisperer/software/chipwhisperer/hardware/naeusb/bootloader_sam3u.py:308, in Samba.chip_id(self)
305 def chip_id(self):
306 “”" Read chip-id “”"
→ 308 vector = self.read_word(0x00)
310 # If the vector is a ARM7TDMI branch, then assume Atmel SAM7 registers
311 if ((vector & 0xff000000) == 0xea000000):

File ~/chipwhisperer/software/chipwhisperer/hardware/naeusb/bootloader_sam3u.py:333, in Samba.read_word(self, addr)
331 if len(resp) < 4:
332 target_logger.debug(“Timeout on read from {:04X}”.format(addr))
→ 333 raise IOError(“timeout”)
335 value = (resp[3] << 24 | resp[2] << 16 | resp[1] << 8 | resp[0] << 0)
336 target_logger.debug(“Read {:04X} from {:02X}”.format(value, addr))

OSError: timeout

Can you post a picture of your CW313 board so that I can see the jumper settings?

Thanks for the quick reply, here’s the board

Hi,

Can you post the output of print(scope) from just before you run the programming command?

Alex

I’m out of town for the week, will share EOW

print(scope) gives me

cwhusky Device
sn             = 50203220325531583130343237323036
fpga_buildtime = 12/11/2024, 12:33
fw_version = 
    major = 1
    minor = 5
    debug = 0
gain = 
    mode = high
    gain = 22
    db   = 25.091743119266056
adc = 
    state                    = False
    basic_mode               = rising_edge
    timeout                  = 2
    offset                   = 0
    presamples               = 0
    samples                  = 5000
    decimate                 = 1
    trig_count               = 2
    stream_mode              = False
    test_mode                = False
    bits_per_sample          = 12
    segments                 = 1
    segment_cycles           = 0
    segment_cycle_counter_en = False
    clip_errors_disabled     = False
    lo_gain_errors_disabled  = False
    errors                   = trigger too soon error, 
clock = 
    clkgen_src             = system
    clkgen_freq            = 7363636.363636363
    adc_mul                = 4
    adc_freq               = 29454545.454545453
    adc_rate               = 29454545.454545453
    freq_ctr               = 0
    freq_ctr_src           = extclk
    clkgen_locked          = True
    adc_phase              = 0.0
    extclk_monitor_enabled = False
    extclk_error           = False
    extclk_tolerance       = 1144409.1796875
trigger = 
    sequencer_enabled = False
    module            = basic
    triggers          = tio4
io = 
    tio1            = serial_rx
    tio2            = serial_tx
    tio3            = high_z
    tio4            = high_z
    pdid            = high_z
    pdic            = high_z
    nrst            = high_z
    glitch_hp       = False
    glitch_lp       = False
    extclk_src      = hs1
    hs2             = clkgen
    target_pwr      = True
    tio_states      = (1, 1, 1, 0)
    cdc_settings    = bytearray(b'\x00\x00\x00\x00')
    aux_io_mcx      = high_z
    glitch_trig_mcx = trigger
glitch = 
    enabled           = False
    num_glitches      = 1
    clk_src           = target
    mmcm_locked       = False
    width             = 0
    offset            = 0
    trigger_src       = manual
    arm_timing        = after_scope
    ext_offset        = 0
    repeat            = 1
    output            = clock_xor
    phase_shift_steps = 4592
SAD = 
    threshold            = 0
    interval_threshold   = 1
    trigger_sample       = 256
    sad_reference_length = 256
    emode                = False
    multiple_triggers    = False
    num_triggers_seen    = 0
    always_armed         = False
ADS4128 = 
    mode      = normal
    low_speed = True
    hi_perf   = 2
LA = 
    present                  = True
    enabled                  = False
    clkgen_enabled           = False
    locked                   = False
    clk_source               = pll
    trigger_source           = glitch
    oversampling_factor      = 1
    sampling_clock_frequency = 0.0
    downsample               = 1
    capture_group            = glitch
    capture_depth            = 0
trace = 
    present      = True
    enabled      = False
    errors       = False
    trace_synced = False
    trace_mode   = parallel
    trace_width  = 4
    clock = 
        fe_clock_alive   = True
        fe_clock_src     = usb_clock
        clkgen_enabled   = False
        fe_freq          = 96000000.0
        swo_clock_locked = False
        swo_clock_freq   = 0.0
    capture = 
        trigger_source         = firmware trigger
        use_husky_arm          = False
        raw                    = True
        rules_enabled          = []
        rules                  = []
        mode                   = while_trig
        count                  = 0
        max_triggers           = 1
        triggers_generated     = 0
        record_syncs           = False
        matched_pattern_data   = 0000000000000000
        matched_pattern_counts = [0, 0, 0, 0, 0, 0, 0, 0]
XADC = 
    status          = good
    temp            = 37.2 [C]
    max_temp        = 38.8 [C]
    temp_trigger    = 80.0 [C]
    temp_reset      = 59.9 [C]
    ot_temp_trigger = 84.9 [C]
    ot_temp_reset   = 59.9 [C]
    vccint          = 1.001 [V]
    vccaux          = 1.805 [V]
    vccbram         = 1.003 [V]
userio = 
    mode            = normal
    direction       = 0
    drive_data      = 0
    status          = 511
    Individual pins = 
        pin D0 = Target-driven, value = 1
        pin D1 = Target-driven, value = 1
        pin D2 = Target-driven, value = 1
        pin D3 = Target-driven, value = 1
        pin D4 = Target-driven, value = 1
        pin D5 = Target-driven, value = 1
        pin D6 = Target-driven, value = 1
        pin D7 = Target-driven, value = 1
        pin CK = Target-driven, value = 1
LEDs = 
    setting = 0 (default, as labelled)
errors = 
    sam_errors      = False
    sam_led_setting = Default
    XADC errors     = False
    ADC errors      = trigger too soon error, 
    extclk error    = False
    trace errors    = False

FYI scope.default_setup() gives me this:

scope.gain.mode                          changed from low                       to high                     
scope.gain.gain                          changed from 0                         to 22                       
scope.gain.db                            changed from 15.0                      to 25.091743119266056       
scope.adc.samples                        changed from 131124                    to 5000                     
scope.clock.clkgen_freq                  changed from 0                         to 7363636.363636363        
scope.clock.adc_freq                     changed from 0                         to 29454545.454545453       
scope.clock.adc_rate                     changed from 0.0                       to 29454545.454545453       
scope.io.tio1                            changed from serial_tx                 to serial_rx                
scope.io.tio2                            changed from serial_rx                 to serial_tx                
scope.io.hs2                             changed from None                      to clkgen                   
scope.io.cdc_settings                    changed from bytearray(b'\x01\x00\x00\x00') to bytearray(b'\x00\x00\x00\x00')
scope.glitch.phase_shift_steps           changed from 0                         to 4592                     
scope.trace.capture.trigger_source       changed from trace trigger, rule #0    to firmware trigger         

I started playing with the labs in sca101 and found by accident that I could run lab 2_1A: I could tun the setup as in compile and upload the firmware and capture a trace. Tryinf to upload a new firmware however results in the same timeout. When I unplug the CW and reset the kernel (sometimes twice) I can get it to work again for once.

Your settings look good, I’m not too sure what’s going on here. Could you try pulling the latest commit and running cw.target_logger.setLevel(cw.logging.DEBUG) before programming?

Yes looks like this

(ChipWhisperer Target DEBUG|File programmers.py:112) Saving ['pdic', 'pdid', 'nrst', 'tio3'] pin configuration
(ChipWhisperer Target DEBUG|File programmers.py:121) pdic was high_z
(ChipWhisperer Target DEBUG|File programmers.py:121) pdid was high_z
(ChipWhisperer Target DEBUG|File programmers.py:121) nrst was high_z
(ChipWhisperer Target DEBUG|File programmers.py:121) tio3 was high_z
(ChipWhisperer Target DEBUG|File programmers.py:126) Changing ['pdic', 'pdid', 'nrst', 'tio3'] pin configuration
(ChipWhisperer Target INFO|File programmers.py:165) Toggling erase(pdic)/nrst pins
(ChipWhisperer Target INFO|File programmers.py:184) Connecting to SAMBA
(ChipWhisperer Target INFO|File serial.py:121) Serial baud rate = 115200
(ChipWhisperer Target INFO|File bootloader_sam3u.py:243) AutoBaud: 
(ChipWhisperer Target INFO|File bootloader_sam3u.py:244) bytearray(b'')
(ChipWhisperer Target INFO|File bootloader_sam3u.py:249) Setting binary mode result: bytearray(b'')
(ChipWhisperer Target DEBUG|File bootloader_sam3u.py:327) Read word from 00
(ChipWhisperer Target DEBUG|File bootloader_sam3u.py:333) Timeout on read from 0000
(ChipWhisperer Target DEBUG|File programmers.py:131) Restoring ['pdic', 'pdid', 'nrst', 'tio3'] pin configuration
(ChipWhisperer Target DEBUG|File programmers.py:133) pdic setting to high_z
(ChipWhisperer Target DEBUG|File programmers.py:133) pdid setting to high_z
(ChipWhisperer Target DEBUG|File programmers.py:133) nrst setting to high_z
(ChipWhisperer Target DEBUG|File programmers.py:133) tio3 setting to high_z

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
Cell In[6], line 4
      1 #cw.program_target(scope, cw.programmers.XMEGAProgrammer, "path/to/firmware.hex")
      2 #cw.program_target(scope, cw.programmers.STM32FProgrammer, "path/to/firmware.hex")
      3 #cw.program_target(scope, cw.programmers.AVRProgrammer, "path/to/firmware.hex")
----> 4 cw.program_target(scope, cw.programmers.SAM4SProgrammer, "../firmware/mcu/simpleserial-base/simpleserial-base-CWHUSKY.hex")

File ~/chipwhisperer/software/chipwhisperer/__init__.py:181, in program_target(scope, prog_type, fw_path, **kwargs)
    179 prog._logging = None
    180 prog.open()
--> 181 prog.find()
    182 prog.erase()
    183 prog.program(fw_path, memtype="flash", verify=True)

File ~/chipwhisperer/software/chipwhisperer/capture/api/programmers.py:129, in save_and_restore_pins.<locals>.func_wrapper(self, *args, **kwargs)
    126 target_logger.debug('Changing {} pin configuration'.format(pin_setup))
    128 try:
--> 129     val = func(self, *args, **kwargs)
    130 finally:
    131     target_logger.debug('Restoring {} pin configuration'.format(pin_setup))

File ~/chipwhisperer/software/chipwhisperer/capture/api/programmers.py:185, in SAM4SProgrammer.find(self, power_cycle)
    183 prog = self.get_prog()
    184 target_logger.info("Connecting to SAMBA")
--> 185 prog.con(self.scope)
    186 target_logger.info("Done!")

File ~/chipwhisperer/software/chipwhisperer/hardware/naeusb/bootloader_sam3u.py:251, in Samba.con(self, port, usbmode)
    248 res = ser.read(2)
    249 target_logger.info("Setting binary mode result: " + str(res))
--> 251 cid = self.chip_id()
    253 target_logger.info('FWUP: CID = %04x' % cid)
    255 #Originally this was used to limit to SAM3U
    256 #eproc = (cid >> 5) & 0x7
    257 #arch = (cid >> 20) & 0xff
    258 #if eproc == 3 and ((0x80 <= arch <= 0x8a) or (0x93 <= arch <= 0x9a)):
    259 #    target_logger.info('FWUP: Detected SAM3')

File ~/chipwhisperer/software/chipwhisperer/hardware/naeusb/bootloader_sam3u.py:309, in Samba.chip_id(self)
    306 def chip_id(self):
    307     """ Read chip-id """
--> 309     vector = self.read_word(0x00)
    311     # If the vector is a ARM7TDMI branch, then assume Atmel SAM7 registers
    312     if ((vector & 0xff000000) == 0xea000000):

File ~/chipwhisperer/software/chipwhisperer/hardware/naeusb/bootloader_sam3u.py:334, in Samba.read_word(self, addr)
    332 if len(resp) < 4:
    333     target_logger.debug("Timeout on read from {:04X}".format(addr))
--> 334     raise IOError("timeout")
    336 value = (resp[3] << 24 | resp[2] << 16 | resp[1] << 8 | resp[0] << 0)
    337 target_logger.debug("Read {:04X} from {:02X}".format(value, addr))

OSError: timeout

It doesn’t look like your SAM4S is responding at all. I’ll play around with the bootloader entry code to see if there’s anything unreliable there.

Thanks Alex. Let me know if I can contribute