# Buggy code
def __call__(self, progress):
    assert progress >= 0.0
    #         assert progress <= 1.0 # TODO restore this assert when the progress > 1 bug is fixed
    #         assert (progress == 0 and self.prev_progress == 1.0) or (progress >= self.prev_progress)

    if progress > 1.0:
        log.debug("progress out of bounds: %.3f", progress)

    # Reset state on 0.0
    if progress == 0.0:
        self._start()

    # Check for backwards progress
    if progress < self.prev_progress:
        self.backwards_progress = True
    self.prev_progress = progress

    # print progress bar
    if not self.done:
        self._update(progress)

        # Finish on 1.0
        if progress >= 1.0:
            self._finish()
            if self.backwards_progress:
                log.warning("Progress went backwards!")


# Traceback (TypeError)
pyocd gdb -t stm32f401re --pack /Users/matost01/Downloads/CMSIS/STM32F4xx_DFP.2.13.0.pack
0000355:INFO:pack_target:Loading CMSIS-Pack: /Users/matost01/Downloads/CMSIS/STM32F4xx_DFP.2.13.0.pack
0000457:INFO:board:Target type is stm32f401re
0000464:WARNING:flash_algo:Not enough space for flash algorithm
0000464:ERROR:__main__:uncaught exception: unsupported operand type(s) for -: 'tuple' and 'int'
Traceback (most recent call last):
File "/Users/matost01/mbed-studio-tools/python/lib/python2.7/site-packages/pyocd/__main__.py", line 304, in run
self._commands[self._args.cmd]()
File "/Users/matost01/mbed-studio-tools/python/lib/python2.7/site-packages/pyocd/__main__.py", line 463, in do_gdbserver
**sessionOptions)
File "/Users/matost01/mbed-studio-tools/python/lib/python2.7/site-packages/pyocd/core/helpers.py", line 196, in session_with_chosen_probe
session = Session(allProbes[0], options=options, **kwargs)
File "/Users/matost01/mbed-studio-tools/python/lib/python2.7/site-packages/pyocd/core/session.py", line 127, in __init__
or Board(self, self._options.get('target_override', None))
File "/Users/matost01/mbed-studio-tools/python/lib/python2.7/site-packages/pyocd/board/board.py", line 47, in __init__
self.target = TARGET[self._target_type](session)
File "/Users/matost01/mbed-studio-tools/python/lib/python2.7/site-packages/pyocd/target/pack/pack_target.py", line 31, in _pack_target__init__
super(self.__class__, self).__init__(session, self._pack_device.memory_map)
File "/Users/matost01/mbed-studio-tools/python/lib/python2.7/site-packages/pyocd/target/pack/cmsis_pack.py", line 454, in memory_map
self._build_flash_regions()
File "/Users/matost01/mbed-studio-tools/python/lib/python2.7/site-packages/pyocd/target/pack/cmsis_pack.py", line 386, in _build_flash_regions
length = nextStart - start
TypeError: unsupported operand type(s) for -: 'tuple' and 'int'```

# Fixed code
def __call__(self, progress):
    assert progress >= 0.0

    # Cap progress at 1.0.
    if progress > 1.0:
        progress = 1.0
        LOG.debug("progress out of bounds: %.3f", progress)

    # Reset state on 0.0
    if progress == 0.0:
        self._start()

    # Check for backwards progress
    if progress < self.prev_progress:
        self.backwards_progress = True
    self.prev_progress = progress

    # print progress bar
    if not self.done:
        self._update(progress)

        # Finish on 1.0
        if progress >= 1.0:
            self.done = True
            self._finish()
            if self.backwards_progress:
                LOG.debug("Progress went backwards!")