Package: kflash
The latest release version will put here, and sync with pip.Usage# kflash --helpusage:kflash.py[-h][-pPORT][-fFLASH][-bBAUDRATE][-lBOOTLOADER][-e][-kKEY][-v][--verbose][-t][-n][-s][-B{kd233,dan,bit,bit_mic,goE,goD,maixduino,trainer}][-S][-AADDR][-LLENGTH][-iIOMODE]firmwarepositionalarguments:firmwarefirmwarebinpathoptionalarguments:-h,--helpshowthishelpmessageandexit-pPORT,--portPORTCOMPort-fFLASH,--flashFLASHSPIFlashtype,0forSPI3,1forSPI0-bBAUDRATE,--baudrateBAUDRATEUARTbaudrateforuploadingfirmware-lBOOTLOADER,--bootloaderBOOTLOADERBootloaderbinpath-e,--eraseEraseflash(chiperase)-kKEY,--keyKEYAESkeyinhex,ifyouneedencryptyourfirmware.-v,--versionPrintversion.--verboseIncreaseoutputverbosity-t,--terminalStartaterminalafterfinish(Pythonminiterm)-n,--noansiDonotuseANSIcolors,recommendedinWindowsCMD-s,--sramDownloadfirmwaretoSRAMandboot-B{kd233,dan,bit,bit_mic,goE,goD,maixduino,trainer},--Board{kd233,dan,bit,bit_mic,goE,goD,maixduino,trainer}Selectdevboard-S,--SlowSlowdownloadmode-AADDR,--addrADDREraseflashaddr-LLENGTH,--lengthLENGTHEraseflashlength-iIOMODE,--iomodeIOMODESPIflashIOmode,diofordualSPI,qioforquadSPIAttentionMaixgo with openec firmware, BOARD must choose-BgoE, and should choose
sencond com port.With cmsis-dap firmware(before 2019.02.21), BOARD must use-BgoD.You can updatenew cmsis-dap firmware, it is same as openec.For K210 Trainer V0.01b, BOARD must choose-Btrainer.For KD233, BOARD must choose-Bkd233, and the jumper for kd233 automatic
download circuit must be set.InstallationIf you installed as a root user, please try:sudopip3install--upgradekflashIf you installed as a non root user, please try:pipinstallkflash--user--upgradeAnd then add${HOME}/.local/binto your${PATH}, .e.g, in your.bashrcor.zshrc.exportPATH=${HOME}/.local/bin:${PATH}If you got an error, please trysudopython-mpipinstall--upgradekflashsudopython3-mpipinstall--upgradekflashsudopipinstall--upgradekflashsudopip2install--upgradekflashFor linux users, first of all, you must add yourself to dialout group.
Or you have to use root permission every time.sudousermod-a-Gdialout$(whoami)For gentoo usersudousermod-a-Guucp$(whoami)Sample Usage# Linux or macOS
# Using pipkflash-Bdanfirmware.binkflash-Bdan-tfirmware.bin# Open a Serial Terminal After Finish
# Using source codepython3kflash.py-Bdanfirmware.binpython3kflash.py-Bdan-tfirmware.bin# Open a Serial Terminal After Finish# Windows CMD or PowerShell
# Using pipkflash-Bdanfirmware.binkflash-Bdan-tfirmware.bin# Open a Serial Terminal After Finishkflash-Bdan-n-tfirmware.bin# Open a Serial Terminal After Finish, do not use ANSI colors
# Using source codepythonkflash.py-Bdanfirmware.binpythonkflash.py-Bdan-tfirmware.bin# Open a Serial Terminal After Finishpythonkflash.py-Bdan-n-tfirmware.bin# Open a Serial Terminal After Finish, do not use ANSI colors# Windows Subsystem for Linux
# Using pipsudokflash-Bdan-p/dev/ttyS13firmware.bin# ttyS13 Stands for the COM13 in Device Managersudokflash-Bdan-p/dev/ttyS13-tfirmware.bin# Open a Serial Terminal After Finish
# Using source codesudopython3kflash.py-Bdan-p/dev/ttyS13firmware.bin# ttyS13 Stands for the COM13 in Device Managersudopython3kflash.py-Bdan-p/dev/ttyS13-tfirmware.bin# Open a Serial Terminal After FinishFor fast programming,# Using pip
# This will enable opoenec super-baudrate!kflash-b4500000-BgoEfirmware.bin# Trainer could use 8000000 baudrate!kflash-b8000000-Btrainerfirmware.bin# Dan could use 3000000 baudrate!kflash-b3000000-Bdanfirmware.bin# Using source code
# This will enable opoenec super-baudrate!python3kflash.py-b4500000-BgoEfirmware.bin# Trainer could use 8000000 baudrate!python3kflash.py-b8000000-Btrainerfirmware.bin# Dan could use 3000000 baudrate!python3kflash.py-b3000000-Bdanfirmware.binExecute user code directly in SRAM and view in serial terminal,# Using pip
# For `.elf` filekflash-b115200-BgoE-s-thello_world# For `.bin` filekflash-b115200-BgoE-s-thello_world.bin# Using source code
# For `.elf` filepython3kflash.py-b115200-BgoE-s-thello_world# For `.bin` filepython3kflash.py-b115200-BgoE-s-thello_world.binErase flash before download firmware, use -e (–erase) option to do chip erase before download firmware,
or use the erase command to erase a specific address and length without download firmware.python3kflash.py-e-Bbit-b1500000-p/dev/ttyUSB0hello_world.binpython3kflash.py-b115200-p/dev/ttyUSB0erase--addr0x00011000--length0x1000Select SPI I/O mode by use –iomode option.
dio is set flash mode to Dual SPI, the Dual SPI serial throughput rates reach around 20 Mbps.
qio is set flash mode to Quad SPI, the Quad SPI serial throughput rates reach around 40 Mbps.Usually DIO mode has better compatibility and QIO mode has faster speed.
If you find that your k210 cannot boot, you can try DIO mode.python3kflash.py-idio-Bbit-b1500000-p/dev/ttyUSB0hello_world.binpython3kflash.py-iqio-Bbit-b1500000-p/dev/ttyUSB0hello_world.binRequirementspython>=3 or python=2.7pyserial>=3.4pyelftools>=0.25Python3 is recommended.If your python version below python3.6, you need upgrade python at least python 3.6.Windows RequirementsDownload and InstallPython3 at python.orgDownload theget-pip.py at https://bootstrap.pypa.io/get-pip.pyStart CMD or PowerShell Terminal and run the following commandpythonget-pip.pypython-mpipinstallpyserialpython-mpipinstallpyelftoolsmacOS Requirements# Install Homebrew, an awesome package manager for macOS/usr/bin/ruby-e"$(curl-fsSLhttps://raw.githubusercontent.com/Homebrew/install/master/install)"brewinstallpythonpython3-mpip3installpyserialpython3-mpip3installpyelftoolsUbuntu, Debian Requirementssudoaptupdatesudoaptinstallpython3python3-pipsudopip3installpyserialsudopip3installpyelftoolsFedorasudodnfinstallpython3sudopython3-mpipinstallpyserialsudopython3-mpipinstallpyelftoolsCentOSsudoyum-yinstallepel-releasesudoyum-yinstallpython36upython36u-pipsudoln-s/bin/python3.6/usr/bin/python3sudoln-s/bin/pip3.6/usr/bin/pip3sudopip3installpyserialsudopip3installpyelftoolsTrouble ShootingCould not open port /dev/tty*: [Errno 13] Permission denied: ‘/dev/tty*’For Windows Subsystem for Linux, you may have to use sudo due to its docker
like featureAdd your self to a dialout group to use usb-to-uart devices bysudousermod-a-Gdialout$(whoami)Logout, and log in.UART Auto Detecting is Not Working, or Select the Wrong UART PortWindowsCheck the COM Number for your device at the Device Manager, such asUSB-SERIAL CH340(COM13).# Using pip, only need once when you installpipinstallkflashkflash-pCOM13firmware.bin# Orkflash.exe-pCOM13firmware.bin# Using source codepythonkflash.py-pCOM13firmware.binWindows Subsystem For Linux(WSL)Check the COM Number for your device at the Device Manager, such asUSB-SERIAL CH340(COM13).# Using pip, only need once when you installsudopip3installkflashsudokflash-p/dev/ttyS13firmware.bin# You have to use *sudo* here
# Using source codesudopython3kflash.py-p/dev/ttyS13firmware.bin# You have to use *sudo* hereLinuxCheck the USB Device Name, Usually presented as ttyUSB*ls/dev/ttyUSB*It will print :$ls/dev/ttyUSB*/dev/ttyUSB0/dev/ttyUSB2/dev/ttyUSB13Choose the one you think belongs to your device, or you may try multimule
names.# Using pippython3kflash.py-p/dev/ttyUSB13firmware.bin# Using source codekflash-p/dev/ttyUSB13firmware.binmacOSCheck the USB Device Name, Usually presented as cu.*ls/dev/cu.*It will print :$ls/dev/ttyUSB*/dev/cu.wchusbserial1410/dev/cu.wchusbserial1437/dev/cu.SLAB_USBtoUART2333Choose the one you think belongs to your device, or you may try multimule
names.# Using pipkflash-p/dev/cu.wchusbserial1410firmware.bin# Using source codepython3kflash.py-p/dev/cu.wchusbserial1410firmware.binYou may unable to find the device even in the /dev, check the link below for
driversFor K210 and Sipeed Dan ->WCH CH34x USB2UART Chip