pymcuprog.serialupdi package

Submodules

pymcuprog.serialupdi.application module

Application layer for UPDI stack

class pymcuprog.serialupdi.application.UpdiApplication(serialport, baud, device=None, timeout=None)

Bases: object

Generic application layer for UPDI

enter_progmode()

Enters into NVM programming mode

in_prog_mode()

Checks whether the NVM PROG flag is up

leave_progmode()

Disables UPDI which releases any keys enabled

read_data(address, size)

Reads a number of bytes of data from UPDI

Parameters:
  • address – address to write to

  • size – number of bytes to read

read_data_words(address, words)

Reads a number of words of data from UPDI

Parameters:
  • address – address to write to

  • words – number of words to read

read_device_info()

Reads out device information from various sources

reset(apply_reset)

Applies or releases an UPDI reset condition

Parameters:

apply_reset – True to apply, False to release

unlock()

Unlock by chip erase

wait_unlocked(timeout_ms)

Waits for the device to be unlocked. All devices boot up as locked until proven otherwise

Parameters:

timeout_ms – number of milliseconds to wait

wait_urow_prog(timeout_ms, wait_for_high)

Waits for the device to be in user row write mode User row is writeable on a locked device using this mechanism

Parameters:
  • timeout_ms – number of milliseconds to wait

  • wait_for_high – set True to wait for bit to go high; False to wait for low

write_data(address, data)

Writes a number of bytes to memory

Parameters:
  • address – address to write to

  • data – data to write

write_data_words(address, data)

Writes a number of words to memory

Parameters:
  • address – address to write to

  • data – data to write

write_user_row_locked_device(address, data)

Writes data to the user row when the device is locked, using a key.

pymcuprog.serialupdi.application.decode_sib(sib)

Turns the SIB into something readable

Parameters:

sib – SIB data to decode

pymcuprog.serialupdi.constants module

UPDI protocol constants

pymcuprog.serialupdi.nvm module

NVM implementations on various UPDI device families

class pymcuprog.serialupdi.nvm.NvmUpdi(readwrite, device)

Bases: object

Base class for NVM

chip_erase()

Does a chip erase using the NVM controller

erase_eeprom()

Erase EEPROM memory only

erase_flash_page(address)

Erasing single flash page using the NVM controller

Parameters:

address (int) – Start address of page to erase

erase_user_row(address, size)

Erase User Row memory only

Parameters:
  • address (int) – Start address of user row

  • size (int) – Size of user row

execute_nvm_command(command)

Executes an NVM COMMAND on the NVM CTRL

Parameters:

command – command to execute

wait_nvm_ready()

Waits for the NVM controller to be ready

write_eeprom(address, data)

Write data to EEPROM

Parameters:
  • address – address to write to

  • data – data to write

write_flash(address, data)

Writes data to flash

Parameters:
  • address – address to write to

  • data – data to write

write_fuse(address, data)

Writes one fuse value

Parameters:
  • address – address to write to

  • data – data to write

write_user_row(address, data)

Writes data to user row

Parameters:
  • address – address to write to

  • data – data to write

class pymcuprog.serialupdi.nvm.NvmUpdiAvrV2(readwrite, device)

Bases: NvmUpdi

AKA Version 2 UPDI NVM Present on, for example, AVR-DA and newer

chip_erase()

Does a chip erase using the NVM controller Note that on locked devices this it not possible and the ERASE KEY has to be used instead

erase_eeprom()

Erase EEPROM memory only (v1)

erase_flash_page(address)

Erasing single flash page using the NVM controller (v1)

Parameters:

address (int) – Start address of page to erase

erase_user_row(address, size)

Erase User Row memory only (v1)

Parameters:

address (int) – Start address of user row

write_eeprom(address, data)

Writes data to NVM (EEPROM)

Parameters:
  • address – address to write to

  • data – data to write

write_flash(address, data)

Writes data to flash (v1)

Parameters:
  • address – address to write to

  • data – data to write

write_fuse(address, data)

Writes one fuse value V1 fuses are EEPROM-based

Parameters:
  • address – address to write to

  • data – data to write

write_nvm(address, data, use_word_access)

Writes data to NVM (version 1) This version of the NVM block has no page buffer, so words are written directly.

Parameters:
  • address – address to write to

  • data – data to write

  • use_word_access – write in whole words?

write_user_row(address, data)

Writes data to user row (v1)

Parameters:
  • address – address to write to

  • data – data to write

class pymcuprog.serialupdi.nvm.NvmUpdiAvrV3(readwrite, device)

Bases: NvmUpdi

AKA Version 3 UPDI NVM Present on, for example, AVR-EA

chip_erase()

Does a chip erase using the NVM controller

Note that on locked devices this is not possible and the ERASE KEY has to be used instead, see the unlock method

erase_eeprom()

Erase EEPROM memory only

erase_flash_page(address)

Erasing single flash page using the NVM controller (v3)

Parameters:

address (int) – Start address of page to erase

erase_user_row(address, size)

Erase User Row memory only

Parameters:

address (int) – Start address of user row

write_eeprom(address, data)

Write data to EEPROM (v3)

Parameters:
  • address – address to write to

  • data – data to write

write_flash(address, data)

Writes data to flash (v3)

Parameters:
  • address – address to write to

  • data – data to write

write_fuse(address, data)

Writes one fuse value (v3)

Parameters:
  • address – address to write to

  • data – data to write

write_nvm(address, data, use_word_access, nvmcommand=4)

Writes a page of data to NVM (v3)

By default the PAGE_WRITE command is used, which requires that the page is already erased. By default word access is used (flash)

Parameters:
  • address – address to write to

  • data – data to write

  • use_word_access – write whole words?

  • nvmcommand – command to use for commit

write_user_row(address, data)

Writes data to user row (v3)

Parameters:
  • address – address to write to

  • data – data to write

class pymcuprog.serialupdi.nvm.NvmUpdiV0(readwrite, device)

Bases: NvmUpdi

AKA Version 0 UPDI NVM Present on, for example, tiny817 -> mega4809

chip_erase()

Does a chip erase using the NVM controller

Note that on locked devices this is not possible and the ERASE KEY has to be used instead, see the unlock method

erase_eeprom()

Erase EEPROM memory only (v0)

erase_flash_page(address)

Erasing single flash page using the NVM controller (v0)

Parameters:

address (int) – Start address of page to erase

erase_user_row(address, size)

Erase User Row memory only (v0)

Parameters:

address (int) – Start address of user row

write_eeprom(address, data)

Write data to EEPROM (v0)

Parameters:
  • address – address to write to

  • data – data to write

write_flash(address, data)

Writes data to flash (v0)

Parameters:
  • address – address to write to

  • data – data to write

write_fuse(address, data)

Writes one fuse value (v0)

Parameters:
  • address – address to write to

  • data – data to write

write_nvm(address, data, use_word_access, nvmcommand=1)

Writes a page of data to NVM (v0)

By default the PAGE_WRITE command is used, which requires that the page is already erased. By default word access is used (flash)

Parameters:
  • address – address to write to

  • data – data to write

  • use_word_access – write whole words?

  • nvmcommand – command to use for commit

write_user_row(address, data)

Writes data to user row (v0)

Parameters:
  • address – address to write to

  • data – data to write

pymcuprog.serialupdi.physical module

Serial driver for UPDI stack

class pymcuprog.serialupdi.physical.UpdiPhysical(port, baud=115200, timeout=None)

Bases: object

PDI physical driver using a given serial port at a given baud

initialise_serial(port, baud, timeout)

Standard serial port initialisation

Parameters:
  • port (str) – Serial port name to connect to

  • baud (int) – Baud rate in bps to use for communications

  • timeout (float) – Timeout value for serial reading. When UPDI is not enabled, attempting to read will return after this timeout period.

receive(size)

Receives a frame of a known number of chars from UPDI

Parameters:

size – bytes to receive

send(command)

Sends a char array to UPDI without inter-byte delay Note that the byte will echo back

Parameters:

command – command to send

send_double_break()

Sends a double break to reset the UPDI port

BREAK is actually just a slower zero frame A double break is guaranteed to push the UPDI state machine into a known state, albeit rather brutally

sib()

System information block is just a string coming back from a SIB command

pymcuprog.serialupdi.readwrite module

Read/write access provider for UPDI

class pymcuprog.serialupdi.readwrite.UpdiReadWrite(datalink)

Bases: object

Provides various forms of reads and writes for UPDI applications Makes us of the datalink provided

read_byte(address)

Read a single byte from UPDI

Parameters:

address – address to read from

Returns:

value read

read_cs(address)

Read from Control/Status space

Parameters:

address – address (index) to read

Returns:

value read

read_data(address, size)

Reads a number of bytes of data from UPDI

Parameters:
  • address – address to write to

  • size – number of bytes to read

read_data_words(address, words)

Reads a number of words of data from UPDI

Parameters:
  • address – address to write to

  • words – number of words to read

read_sib()

Read the SIB from UPDI

Returns:

SIB string (bytearray) read

write_byte(address, value)

Writes a single byte to UPDI

Parameters:
  • address – address to write to

  • value – value to write

write_cs(address, value)

Write to Control/Status space

Parameters:
  • address – address (index) to write

  • value – 8-bit value to write

write_data(address, data)

Writes a number of bytes to memory

Parameters:
  • address – address to write to

  • data – data to write

write_data_words(address, data)

Writes a number of words to memory

Parameters:
  • address – address to write to

  • data – data to write

write_key(size, key)

Write a KEY into UPDI

Parameters:
  • size – size of key to send

  • key – key value

pymcuprog.serialupdi.timeout module

Simple timer helper for UPDI stack

class pymcuprog.serialupdi.timeout.Timeout(timeout_ms)

Bases: object

Simple timeout helper in milliseconds.

expired()

Check if the timeout has expired

Module contents