ページ更新: 2014-09-15 (月) (1681日前)

関連: 組み込み/STM32

(新規作成 2014-09-15)

Micro Python についてのメモ。

目次

[編集]

情報源 #

DFU (Device Class Specification for Device Firmware Upgrade, Version 1.1, Aug 5, 2004)

[編集]

メモ #

[編集]

ビルド (2014-09-15) #

Ubuntu 14.04 x64 を使った。 この作業を行う前に、build-essential, git, emacs をインストールしていた。

ソースコードを micropython/micropython · GitHub から取得:

$ git clone https://github.com/micropython/micropython.git
$ cd micropython/stmhal

ビルド……コンパイラが無いので、失敗:

$ make BOARD=STM32F4DISC
Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.
mkdir -p build-STM32F4DISC/genhdr
Create build-STM32F4DISC/pins_qstr.h
CPP ../py/qstrdefs.h
make: arm-none-eabi-gcc: コマンドが見つかりませんでした
make: *** [build-STM32F4DISC/genhdr/qstrdefs.generated.h] エラー 127

コンパイラを調べて、arm-none-eabi-gcc をインストール:

$ apt-cache search ^gcc- | grep eabi
gcc-4.8-arm-linux-gnueabihf - GNU C コンパイラ
gcc-4.8-arm-linux-gnueabihf-base - GCC - GNU コンパイラコレクション (基本パッケージ)
gcc-4.8-multilib-arm-linux-gnueabihf - GNU C compiler (multilib files)
gcc-arm-linux-gnueabihf - The GNU C compiler for armhf architecture
gcc-arm-linux-androideabi - cross toolchain and binutils for Android/Bionic on ARM
gcc-arm-none-eabi - GCC cross compiler for ARM Cortex-A/R/M processors
gcc-4.7-arm-linux-gnueabi - GNU C compiler
gcc-4.7-arm-linux-gnueabi-base - GCC - GNU コンパイラコレクション (基本パッケージ)
gcc-4.7-arm-linux-gnueabihf - GNU C compiler
gcc-4.7-arm-linux-gnueabihf-base - GCC - GNU コンパイラコレクション (基本パッケージ)
gcc-4.7-multilib-arm-linux-gnueabi - GNU C compiler (multilib files)
gcc-4.7-multilib-arm-linux-gnueabihf - GNU C compiler (multilib files)
gcc-arm-linux-gnueabi - The GNU C compiler for armel architecture

$ sudo apt-get install gcc-arm-none-eabi

ビルドやり直し。所要時間は約1分

$ make BOARD=STM32F4DISC
Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.
CPP ../py/qstrdefs.h
makeqstrdata ../py/qstrdefs.h qstrdefsport.h build-STM32F4DISC/pins_qstr.h
Generating build-STM32F4DISC/genhdr/py-version.h
mkdir -p build-STM32F4DISC/cc3k
mkdir -p build-STM32F4DISC/fatfs/src
mkdir -p build-STM32F4DISC/fatfs/src/option
mkdir -p build-STM32F4DISC/hal/src
mkdir -p build-STM32F4DISC/lib/libm
mkdir -p build-STM32F4DISC/py
mkdir -p build-STM32F4DISC/py/../extmod
mkdir -p build-STM32F4DISC/usbdev/class/cdc_msc_hid/src
mkdir -p build-STM32F4DISC/usbdev/core/src
CC ../py/nlrx86.S
CC ../py/nlrx64.S
CC ../py/nlrthumb.S
CC ../py/nlrsetjmp.c
CC ../py/malloc.c
CC ../py/gc.c
CC ../py/qstr.c
CC ../py/vstr.c
CC ../py/unicode.c
CC ../py/mpz.c
CC ../py/lexer.c
CC ../py/lexerstr.c
CC ../py/lexerunix.c
CC ../py/parse.c
CC ../py/parsehelper.c
CC ../py/scope.c
CC ../py/compile.c
CC ../py/emitcommon.c
CC ../py/emitpass1.c
CC ../py/emitcpy.c
CC ../py/emitbc.c
CC ../py/asmx64.c
CC ../py/emitnative.c
CC ../py/asmx86.c
CC ../py/emitnative.c
CC ../py/asmthumb.c
CC ../py/emitnative.c
CC ../py/emitinlinethumb.c
CC ../py/asmarm.c
CC ../py/emitnative.c
CC ../py/formatfloat.c
CC ../py/parsenumbase.c
CC ../py/parsenum.c
CC ../py/emitglue.c
CC ../py/runtime.c
CC ../py/nativeglue.c
CC ../py/stackctrl.c
CC ../py/argcheck.c
CC ../py/map.c
CC ../py/obj.c
CC ../py/objarray.c
CC ../py/objbool.c
CC ../py/objboundmeth.c
CC ../py/objcell.c
CC ../py/objclosure.c
CC ../py/objcomplex.c
CC ../py/objdict.c
CC ../py/objenumerate.c
CC ../py/objexcept.c
CC ../py/objfilter.c
CC ../py/objfloat.c
CC ../py/objfun.c
CC ../py/objgenerator.c
CC ../py/objgetitemiter.c
CC ../py/objint.c
CC ../py/objint_longlong.c
CC ../py/objint_mpz.c
CC ../py/objlist.c
CC ../py/objmap.c
CC ../py/objmodule.c
CC ../py/objobject.c
CC ../py/objproperty.c
CC ../py/objnone.c
CC ../py/objnamedtuple.c
CC ../py/objrange.c
CC ../py/objreversed.c
CC ../py/objset.c
CC ../py/objslice.c
CC ../py/objstr.c
CC ../py/objstrunicode.c
CC ../py/objstringio.c
CC ../py/objtuple.c
CC ../py/objtype.c
CC ../py/objzip.c
CC ../py/opmethods.c
CC ../py/sequence.c
CC ../py/stream.c
CC ../py/binary.c
CC ../py/builtin.c
CC ../py/builtinimport.c
CC ../py/builtinevex.c
CC ../py/builtintables.c
CC ../py/modarray.c
CC ../py/modcollections.c
CC ../py/modgc.c
CC ../py/modio.c
CC ../py/modmath.c
CC ../py/modcmath.c
CC ../py/modmicropython.c
CC ../py/modstruct.c
CC ../py/modsys.c
CC ../py/vm.c
CC ../py/bc.c
CC ../py/showbc.c
CC ../py/repl.c
CC ../py/smallint.c
CC ../py/pfenv.c
CC ../py/pfenv_printf.c
CC ../py/../extmod/moductypes.c
CC ../py/../extmod/modzlibd.c
CC ../lib/libm/math.c
CC ../lib/libm/mathsincos.c
CC ../lib/libm/asinfacosf.c
CC ../lib/libm/atanf.c
CC ../lib/libm/atan2f.c
CC ../lib/libm/fmodf.c
Create build-STM32F4DISC/genhdr/pybcdc.inf
Create build-STM32F4DISC/genhdr/pybcdc_inf.h
CC main.c
CC string0.c
CC system_stm32f4xx.c
CC stm32f4xx_it.c
CC stm32f4xx_hal_msp.c
CC usbd_conf.c
CC usbd_desc_cdc_msc.c
CC usbd_cdc_interface.c
CC usbd_msc_storage.c
CC irq.c
CC pendsv.c
CC systick.c
CC timer.c
CC led.c
CC pin.c
CC pin_defs_stmhal.c
CC pin_named_pins.c
CC bufhelper.c
CC i2c.c
CC spi.c
CC uart.c
CC usb.c
CC printf.c
CC gccollect.c
CC pybstdio.c
CC readline.c
CC pyexec.c
CC help.c
CC input.c
CC modos.c
CC modpyb.c
CC modstm.c
CC modtime.c
CC modselect.c
CC import.c
CC lexerfatfs.c
CC extint.c
CC usrsw.c
CC rng.c
CC rtc.c
CC flash.c
CC storage.c
CC file.c
CC sdcard.c
CC diskio.c
CC ffconf.c
CC lcd.c
CC accel.c
CC servo.c
CC dac.c
CC adc.c
CC pybwlan.c
AS startup_stm32f40xx.s
AS gchelper.s
CC hal/src/stm32f4xx_hal.c
CC hal/src/stm32f4xx_hal_adc.c
CC hal/src/stm32f4xx_hal_adc_ex.c
CC hal/src/stm32f4xx_hal_cortex.c
CC hal/src/stm32f4xx_hal_dac.c
CC hal/src/stm32f4xx_hal_dac_ex.c
CC hal/src/stm32f4xx_hal_dma.c
CC hal/src/stm32f4xx_hal_flash.c
CC hal/src/stm32f4xx_hal_flash_ex.c
CC hal/src/stm32f4xx_hal_gpio.c
CC hal/src/stm32f4xx_hal_i2c.c
CC hal/src/stm32f4xx_hal_pcd.c
CC hal/src/stm32f4xx_hal_pcd_ex.c
CC hal/src/stm32f4xx_hal_rcc.c
CC hal/src/stm32f4xx_hal_rcc_ex.c
CC hal/src/stm32f4xx_hal_rng.c
CC hal/src/stm32f4xx_hal_rtc.c
CC hal/src/stm32f4xx_hal_rtc_ex.c
CC hal/src/stm32f4xx_hal_sd.c
CC hal/src/stm32f4xx_hal_spi.c
CC hal/src/stm32f4xx_hal_tim.c
CC hal/src/stm32f4xx_hal_tim_ex.c
CC hal/src/stm32f4xx_hal_uart.c
CC hal/src/stm32f4xx_ll_sdmmc.c
CC hal/src/stm32f4xx_ll_usb.c
CC usbdev/core/src/usbd_core.c
CC usbdev/core/src/usbd_ctlreq.c
CC usbdev/core/src/usbd_ioreq.c
CC usbdev/class/cdc_msc_hid/src/usbd_cdc_msc_hid.c
CC usbdev/class/cdc_msc_hid/src/usbd_msc_bot.c
CC usbdev/class/cdc_msc_hid/src/usbd_msc_scsi.c
CC usbdev/class/cdc_msc_hid/src/usbd_msc_data.c
CC fatfs/src/ff.c
CC fatfs/src/option/ccsbcs.c
CC cc3k/cc3000_common.c
CC cc3k/evnt_handler.c
CC cc3k/hci.c
CC cc3k/netapp.c
CC cc3k/nvmem.c
CC cc3k/security.c
CC cc3k/socket.c
CC cc3k/wlan.c
CC cc3k/ccspi.c
CC cc3k/pybcc3k.c
CC build-STM32F4DISC/pins_STM32F4DISC.c
LINK build-STM32F4DISC/firmware.elf
   text    data     bss     dec     hex filename
 223300     392   27396  251088   3d4d0 build-STM32F4DISC/firmware.elf
Create build-STM32F4DISC/firmware.dfu
Create build-STM32F4DISC/firmware.hex

バイナリなど。

$ ls -l build-STM32F4DISC/firmware.*
-rw-rw-r-- 1 discypus discypus 224009  9月 15 20:00 build-STM32F4DISC/firmware.dfu
-rwxrwxr-x 1 discypus discypus 456878  9月 15 20:00 build-STM32F4DISC/firmware.elf*
-rw-rw-r-- 1 discypus discypus 629269  9月 15 20:00 build-STM32F4DISC/firmware.hex
-rw-rw-r-- 1 discypus discypus 939950  9月 15 20:00 build-STM32F4DISC/firmware.map

Device firmware update USB programmer をインストールして STM32-F4DISCOVERY の設定を追加する。

$ apt-cache show dfu-util
Package: dfu-util
Priority: extra
Section: universe/electronics
Installed-Size: 83
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Uwe Hermann <uwe@debian.org>
Architecture: amd64
Version: 0.5-1
Depends: libc6 (>= 2.7), libusb-1.0-0 (>= 2:1.0.9~rc3)
Filename: pool/universe/d/dfu-util/dfu-util_0.5-1_amd64.deb
Size: 25042
MD5sum: 8824a8e8c25e2f42e88c631615def007
SHA1: 8cd9b9d2838aca26c569275e05f7459cb9b99fc9
SHA256: 6c4186ad303c171eaba35aa30aa2d02321b3d9540f83a12b36fbb1608a425e27
Description-en: Device firmware update (DFU 1.0) USB programmer
 dfu-util is a program that implements the host (PC) side of the USB DFU 1.0
 (Universal Serial Bus Device Firmware Upgrade) protocol.
 .
 Note: At this point only DFU version 1.0 is supported!
 .
 In the OpenMoko project (for example), this program is used to communicate
 with the specially enhanced bootloader u-boot, which implements the DFU
 device side.
Description-md5: 141c0ca5b67225837f1b089feb5a6675
Homepage: http://dfu-util.gnumonks.org/
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Origin: Ubuntu
$ sudo apt-get install dfu-util
$ sudo emacs /etc/udev/49-stmdiscovery.rules

# 0483:5740 - STM32F4 Dsicovery in USB Serial Mode (CN5)
ATTRS{idVendor}=="0483", ATTRS{idProduct}=="5740", ENV{ID_MM_DEVICE_IGNORE}="1"
ATTRS{idVendor}=="0483", ATTRS{idProduct}=="5740", ENV{MTP_NO_PROBE}="1"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="5740", MODE:="0666"
KERNEL=="ttyACM*", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="5740", MODE:="0666"
# 0483:df11 - STM32F4 Discovery in DFU mode (CN5)
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="df11", MODE:="0666"

$ sudo udevadm control --reload-rules

(以下、保留中。手元にSTM32F4DISCOVERYが無いので) (STM32F401 Nucleo なら余ってるのだけどなあ)