Recent

Author Topic: How to build with MBF framework and STM32 [solved]  (Read 1817 times)

MiR

  • Full Member
  • ***
  • Posts: 201
Re: How to build with MBF framework and STM32
« Reply #30 on: January 17, 2021, 01:35:31 pm »
The code you sent works on my Bluepill !!??!!

I just uploaded it in the debugger and the LED blinks. Very strange...

Grasping at straws:

Can you please check, there is usually the pin number of the LED printed on the Silkscreen, does it say PC13? I have a newer Bluepill with USB-C connector, there the LED is on PB2.

You can clone latest, I just added usage of the 8MHz XTAL on the board, perhaps that changes something (Grasping at straws here, too....)

By the way, do you have a spare Raspberry Pi or another BluePill? Then we could build you a Debug Probe, programming embedded devices without a debug probe is for me worse than flying blind....

Michael

petex

  • Jr. Member
  • **
  • Posts: 69
Re: How to build with MBF framework and STM32
« Reply #31 on: January 17, 2021, 02:00:13 pm »
Quote
Can you please check, there is usually the pin number of the LED printed on the Silkscreen, does it say PC13? I have a newer Bluepill with USB-C connector, there the LED is on PB2.

It says PC13 on the silkscreen.

As i said before I compiled a program using the fpcupdeluxe default embedded compiler and that works fine.

Code: Pascal  [Select][+][-]
  1. program project1;
  2.  
  3. {$O-}
  4.  
  5. var
  6.    sensorValue : integer;
  7.  
  8. procedure delay;
  9. var
  10.   i : uint32;
  11. begin
  12.   for i := 0 to 500000 div 5 do
  13.     begin
  14.       asm
  15.         nop   // empty instruction
  16.       end;
  17.     end;
  18. end;
  19.  
  20. begin
  21.   // turn on Port C
  22.   RCC.APB2ENR := RCC.APB2ENR or (%1 shl 4);
  23.  
  24.   // Pin 13 from Port C to Output
  25.   PortC.CRH := $00300000;
  26.  
  27.   // Note: The LED lights up at LOW.
  28.   while true do
  29.     begin
  30.       // Pin 13 - High
  31.       PortC.BSRR := 1 shl 13;
  32.       Delay;
  33.  
  34.       // Pin 13 - Low
  35.       PortC.BRR := 1 shl 13;
  36.       Delay;
  37.     end;
  38.  
  39. end.
  40.  

Quote
By the way, do you have a spare Raspberry Pi or another BluePill? Then we could build you a Debug Probe, programming embedded devices without a debug probe is for me worse than flying blind...

Agreed. I do have another stm32 and pi zero so it would be cool to make up a probe. I would be happier just getting the v. simple example to work before making things more complex and error prone.

Quote
I just uploaded it in the debugger and the LED blinks. Very strange...
Is the file the same as generated in your environment ?

I shall fiddle around and check for obvious signs.....

MiR

  • Full Member
  • ***
  • Posts: 201
Re: How to build with MBF framework and STM32
« Reply #32 on: January 17, 2021, 02:05:46 pm »
What kind of STM? Another Bluepill? If not which chip does the 2nd STM have?

If it is bluepill then converting it should be pretty easy.

verifying size of the code will be difficult now that I have removed all inline code. When you build latest from git then I can check again.
« Last Edit: January 17, 2021, 02:12:26 pm by MiR »

petex

  • Jr. Member
  • **
  • Posts: 69
Re: How to build with MBF framework and STM32
« Reply #33 on: January 17, 2021, 03:03:19 pm »
hello,

success i think..... 8)

Normally the programs start up immediately after download with the boot0 jumper in the progam mode.

I put the jumper back to operational mode and pressed reset and the blink started.

I changed the blink frequency and re-built etc. just to check i wasn't doing anything stoopid and it changed.

So finally I have got the environment to work. Thanks for your help.
Debugging, probes and all that malarkey can wait until a rainy day.



ps.
I got the serial program to run. It is reporting a clock of 80Mhz not 78 as is the spec. ???

Quote
52 -> No Parity Eight Bits, One StopBit
14:12:48.852 ->
14:12:49.840 -> CPU Frequency: 8000000
14:12:49.840 -> Exact Baudrate: 115942 Baud
14:12:49.840 -> No Parity Eight Bits, One StopBit
14:12:49.840 ->
14:12:50.829 -> CPU Frequency: 8000000
14:12:50.829 -> Exact Baudrate: 115942 Baud
14:12:50.829 -> No Parity Eight Bits, One StopBit
14:12:50.829 ->
14:12:51.868 -> CPU Frequency: 8000000
14:12:51.868 -> Exact Baudrate: 115942 Baud
14:12:51.868 -> No Parity Eight Bits, One StopBit
14:12:51.868 ->
14:12:52.860 -> CPU Frequency: 8000000
14:12:52.860 -> Exact Baudrate: 115942 Baud
14:12:52.860 -> No Parity Eight Bits, One StopBit
14:12:52.860 ->
14:12:53.853 -> CPU Frequency: 8000000
14:12:53.853 -> Exact Baudrate: 115942 Baud
14:12:53.853 -> No Parity Eight Bits, One StopBi
« Last Edit: January 17, 2021, 03:14:48 pm by petex »

MiR

  • Full Member
  • ***
  • Posts: 201
Re: How to build with MBF framework and STM32
« Reply #34 on: January 18, 2021, 03:45:58 pm »
Not sure if this helps much, at least you will not need to use serial upload anymore:

Please look here:

https://github.com/Serasidis/STM32_HID_Bootloader

and download ltest release here:

https://github.com/Serasidis/STM32_HID_Bootloader/releases

Once you have flashed this mini-bootloader you can use my

Blinky-BluePill-HIDboot.lpi

file to build the Blinky example, the lpi contains this addition line:

-k-Ttext=0x08000800

which tells the linker that the program should start behind the bootloader.

Works for me on my Mac, First I have to start

./hid-flash Blinky.bin cu.usbmodem

to prepare the upload and then I attach the device with boot1 switch enabled.

The process should be more simple than that, but I did not read all the details as I have a proper debug probe and just tried this tool for fun.

Michael

MiR

  • Full Member
  • ***
  • Posts: 201
Re: How to build with MBF framework and STM32
« Reply #35 on: January 18, 2021, 10:15:57 pm »
Found an UF2 Bootloader for Bluepill:

https://github.com/mmoskal/uf2-stm32f103

Prebuilt binary:

https://github.com/mmoskal/uf2-stm32f103/releases

This also works well for development, the bluepill shows up as a usb-stick and you can simply drop your binary (converted to uf2 format) to the drive.

A press of reset switches between bootloader mode and app mode for me.

I have added a sample lpi file and Blinky.uf2 to the Blinky-BluePill project directory.

You can convert properly built bin files to uf2 with the tool uf2conv.py:

https://github.com/microsoft/uf2/blob/master/utils/uf2conv.py

I am thinking about adding uf2 support to Freepascal, a lot of SAMD21/SAMD51 Boards come with an preinstalled UF2 bootloader.

 

TinyPortal © 2005-2018