WeACT社のstm32関連ボードにSTM32f412RET6が載ったボードがあるのですが、バイナリーが古そうなので2023/11現在での最新バージョンv.1.21.0でビルドしてみました。まず、micropythonとWeACT社のgithubから該当ボードのレポジトリをcloneしました。
ports/stm32/adc.cは以下のようにします。
備忘録として挙げてみました。今回は以上です。それでは。
mkdir -p ~/stm32 cd ~/stm32 git clone https://github.com/WeActStudio/WeActStudio.STM32F4_64Pin_CoreBoard mkdir micropython cd micropython git clone https://github.com/micropython/micropython -b v1.21.0 micropython-v1.21.0 cd micropython-v1.21.0 git submodule update --init cp -a ~/stm32/WeActStudio.STM32F4_64Pin_CoreBoard/Examples/STM32F412/mpy/WeActStudio_F412RE ports/stm32/boards/ざっと眺めると、linkerスクリプト(ports/stm32/boards/stm32f412rx.ld)が現在のmicropythonのレポジトリにないので、まずそこから手をつけました。内容は以下の通りです。
/* GNU linker script for STM32F412rx (512KB flash, 256kB RAM) */ /* Specify the memory areas */ MEMORY { FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 512K /* entire flash */ FLASH_ISR (rx) : ORIGIN = 0x08000000, LENGTH = 16K /* sector 0 */ FLASH_FS (rx) : ORIGIN = 0x08004000, LENGTH = 112K /* sectors 1,2,3 = 16K:sector 4 = 64K. 16K+16K+16K+64K=48K+64K=112K */ FLASH_TEXT (rx) : ORIGIN = 0x08020000, LENGTH = 384K /* sectors 5,6,7 are 128K */ RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 240K FS_CACHE (xrw) : ORIGIN = 0x2003c000, LENGTH = 16K } /* produce a link error if there is not this amount of RAM for these sections */ _minimum_stack_size = 2K; _minimum_heap_size = 16K; /* Define the stack. The stack is full descending so begins just above last byte of RAM. Note that EABI requires the stack to be 8-byte aligned for a call. */ _estack = ORIGIN(RAM) + LENGTH(RAM) - _estack_reserve; _sstack = _estack - 16K; /* tunable */ /* RAM extents for the garbage collector */ _ram_start = ORIGIN(RAM); _ram_end = ORIGIN(RAM) + LENGTH(RAM); _heap_start = _ebss; /* heap starts just after statically allocated memory */ _heap_end = _sstack; /* Filesystem cache in RAM, and storage in flash */ _micropy_hw_internal_flash_storage_ram_cache_start = ORIGIN(FS_CACHE); _micropy_hw_internal_flash_storage_ram_cache_end = ORIGIN(FS_CACHE) + LENGTH(FS_CACHE); _micropy_hw_internal_flash_storage_start = ORIGIN(FLASH_FS); _micropy_hw_internal_flash_storage_end = ORIGIN(FLASH_FS) + LENGTH(FLASH_FS);つづいてmpy-crossをビルドします。
cd mpy-cross make -j6 cd ..あとは修正を以下の2ファイルに対して行います。
ports/stm32/adc.cは以下のようにします。
変更前 154 #elif defined(STM32F411xE) || defined(STM32F412Zx) || \ 変更後 154 #elif defined(STM32F411xE) || defined(STM32F412Rx) || defined(STM32F412Zx) || \ports/stm32/timer.cは以下のようにします。
変更前 868 #if defined(STM32F412Zx) || defined(STM32L1) 変更後 868 #if defined(STM32F412Rx) || defined(STM32F412Zx) || defined(STM32L1)これでビルドは通ります。
cd ports/stm32 make DEBUG=0 LTO=1 BOARD=WeActStudio_F412RE MICROPY_ROM_TEXT_COMPRESSION=1 CROSS_COMPILE=arm-none-eabi- -j 6 (中略) LINK build-WeActStudio_F412RE/firmware.elf text data bss dec hex filename 320316 52 27784 348152 54ff8 build-WeActStudio_F412RE/firmware.elf GEN build-WeActStudio_F412RE/firmware0.bin GEN build-WeActStudio_F412RE/firmware1.bin GEN build-WeActStudio_F412RE/firmware.he GEN build-WeActStudio_F412RE/firmware.dfu起動させてみたところ、今のところ問題なく動いています。F412REはCPUクロックは遅いものの、RAMが256KB、Flashが512KBあり価格も手ごろなので重宝しそうです。
備忘録として挙げてみました。今回は以上です。それでは。
コメント
コメントを投稿