[STM32F103] - Porting MicroPython to the "BluePill" board

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
slurdge
Posts: 3
Joined: Wed Nov 29, 2017 5:04 pm

Re: [STM32F103] - Porting MicroPython to the "BluePill" board

Post by slurdge » Wed Nov 29, 2017 5:34 pm

Hello everyone, I took a look at continuing the effort of porting micropython. I mostly continued from the work here https://github.com/mcauser/BLUE_PILL_F103C8 done by @mcauser.

I didn't notice the other repositories so I also got the stm32cube fw into the right folder (didn't change it).
There are many function that are not available on the STM32F103, so I had a two step approach:
- For functions that I could patch, I did
- For files with too many errors, I removed them from the build.

I also had to remove startup_stm32.o from Makefile in order to get past linking stage (of course, it produces an empty .dfu file but it's useful for porting).

I pushed everything on my fork on https://github.com/slurdge/micropython/commits/master

I have several questions: it seems that a lot a functionality used by the stm32 port is not actually available, what is the best way to disable them for this port? Do you think we can get under 128K?
Am I duplicating effort here?

slurdge
Posts: 3
Joined: Wed Nov 29, 2017 5:04 pm

Re: [STM32F103] - Porting MicroPython to the "BluePill" board

Post by slurdge » Fri Dec 01, 2017 2:35 pm

Follow up: I was able, with extreme porting in some cases (defining some constants to 0, etc.) to produce a full elf file.
All commits are here: https://github.com/slurdge/micropython/commits/master

However, I have a file that is too big, as the elf gives the following information (for strange reason BBCode isn't available):

~/micropython/ports/stm32 $ arm-none-eabi-readelf -e build-BLUE_PILL_F103C8/firmware.elf
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: ARM
Version: 0x1
Entry point address: 0x802b4ad
Start of program headers: 52 (bytes into file)
Start of section headers: 513684 (bytes into file)
Flags: 0x5000200, Version5 EABI, soft-float ABI
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 5
Size of section headers: 40 (bytes)
Number of section headers: 13
Section header string table index: 12

Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] .isr_vector PROGBITS 08000000 010000 003a54 00 AX 0 0 4
[ 2] .text PROGBITS 08004000 014000 03bf98 00 AX 0 0 4
[ 3] .data PROGBITS 20000000 050000 000068 00 WA 0 0 4
[ 4] .bss NOBITS 20000068 050068 001248 00 WA 0 0 8
[ 5] .heap NOBITS 200012b0 0512b0 002000 00 WA 0 0 1
[ 6] .stack NOBITS 200032b0 0532b0 000400 00 WA 0 0 1
[ 7] .ARM.attributes ARM_ATTRIBUTES 00000000 050068 000031 00 0 0 1
[ 8] .comment PROGBITS 00000000 050099 00007f 01 MS 0 0 1
[ 9] .debug_frame PROGBITS 00000000 050118 000288 00 0 0 4
[10] .symtab SYMTAB 00000000 0503a0 01ead0 10 11 6462 4
[11] .strtab STRTAB 00000000 06ee70 00e7b8 00 0 0 1
[12] .shstrtab STRTAB 00000000 07d628 00006b 00 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
L (link order), O (extra OS processing required), G (group), T (TLS),
C (compressed), x (unknown), o (OS specific), E (exclude),
y (purecode), p (processor specific)

Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x010000 0x08000000 0x08000000 0x03a54 0x03a54 R E 0x10000
LOAD 0x014000 0x08004000 0x08004000 0x3bf98 0x3bf98 R E 0x10000
LOAD 0x050000 0x20000000 0x0803ff98 0x00068 0x012b0 RW 0x10000
LOAD 0x0512b0 0x200012b0 0x08040000 0x00000 0x02000 RW 0x10000
LOAD 0x0532b0 0x200032b0 0x08040000 0x00000 0x00400 RW 0x10000

Section to Segment mapping:
Segment Sections...
00 .isr_vector
01 .text
02 .data .bss
03 .heap
04 .stack


As you can see the size, is 0x3bf98 which is a bit too much... How should I reduce it?
Last edited by slurdge on Fri Dec 01, 2017 10:19 pm, edited 1 time in total.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: [STM32F103] - Porting MicroPython to the "BluePill" board

Post by dhylands » Fri Dec 01, 2017 6:19 pm

Due to the extreme cutting that needs to be done, you're probably better off to start with the minimal port and add in things you need. Building the minimal image (using make CROSS=1) yields:

Code: Select all

LINK build/firmware.elf
   text	   data	    bss	    dec	    hex	filename
  72564	      4	   2528	  75096	  12558	build/firmware.elf

slurdge
Posts: 3
Joined: Wed Nov 29, 2017 5:04 pm

Re: [STM32F103] - Porting MicroPython to the "BluePill" board

Post by slurdge » Fri Dec 01, 2017 9:53 pm

I see... I hoped to stay inside the stm32 tree but I'll try a simple port with help of STM HAL.

mhwang1973
Posts: 9
Joined: Tue Jul 11, 2017 9:35 am

Re: [STM32F103] - Porting MicroPython to the "BluePill" board

Post by mhwang1973 » Sun Dec 24, 2017 3:19 pm

The firmware is built successful, but it is too big to deploy.

victagayun
Posts: 9
Joined: Fri Oct 26, 2018 1:38 am

Re: [STM32F103] - Porting MicroPython to the "BluePill" board

Post by victagayun » Sun Feb 10, 2019 12:17 am

Hello, noob here.
For most noob, they would start using CubeMX then use an IDE like TrueStudio.
Maybe from there, you could modify main.c and add files to do "minimum" gpio and and UART like viewtopic.php?f=12&t=3813#p21957.
What are the steps to do this?

User avatar
mcauser
Posts: 507
Joined: Mon Jun 15, 2015 8:03 am

Re: [STM32F103] - Porting MicroPython to the "BluePill" board

Post by mcauser » Sun Feb 10, 2019 2:24 am

I haven't touched it in a while, but I'd really like to get this one working:
https://github.com/mcauser/BLUE_BUTTON_F103RET6
Costs 4x more than the $3 "Blue Pill", but gives you 512 KByte Flash over the 64 KByte on the blue pill and a bunch more features and IO. I gave it the name "Blue Button" as it appears to be made by the same fabricator(s) as the blue pill and it has a unique blue push button. "Yellow JTAG" didn't have the same ring to it...

If you're going to spend $10 on a F103RET6 dev board, for an additional $4 you can get a much more powerful F407VET6 board.
72 vs 168MHz. The F407 is very similar to the F405 as the pyboard uses.
https://github.com/mcauser/BLACK_F407VE

Since most of the Blue Pill boards use a F103C8T6 chip (64k / 20k), you may be able to swap it for a F103CBT6 (128k / 20k).
Both are 48-pin LQFP/QFN. Not sure if they are pin compatible - you'd have to check the datasheet. A lot of effort and expense for little gain.
https://www.st.com/en/microcontrollers/ ... tId=LN1565
The F103CBT6 (128k / 20k) is used on the Maple Mini (and clones), so buying one of those sounds a lot easier than (de)soldering cpus.

bellad
Posts: 96
Joined: Tue May 14, 2019 1:47 pm

Re: [STM32F103] - Porting MicroPython to the "BluePill" board

Post by bellad » Mon Sep 14, 2020 7:04 am

hello,
the dfu file exist for 'blue pill' ?
if yes , which one to download on http://micropython.org/download/stm32/

thank you

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: [STM32F103] - Porting MicroPython to the "BluePill" board

Post by dhylands » Mon Sep 14, 2020 3:38 pm

Given that the blue pill only has 64K flash in pet sure you won’t be able to get even minimal micropython to run.

I have some info on flashing DFU onto the blue pill over here: https://github.com/dhylands/stm32-test/ ... 2F103-Mini

Note that using the DFU boot loader reduces your available flash from 64K down to 56K.

bellad
Posts: 96
Joined: Tue May 14, 2019 1:47 pm

Re: [STM32F103] - Porting MicroPython to the "BluePill" board

Post by bellad » Tue Sep 15, 2020 6:34 am

Thank you dhylands , regrettably i not understand ( my english is very bad ) .
with your mini dfu , how can i program ?
i just need input / output pin ( 12 input , 14 output )
ex :

Code: Select all

if pin a1 == 1 :
   pin b1 == o 
etc...
thank you for your help

Post Reply