[SOLVED] Bootloader for a mini-PLC with STM32F103VE w/ 16MHz crystal

STM32duino bootloader aka Maple bootloader
BlackBrix
Posts: 31
Joined: Wed Dec 06, 2017 7:49 am

Re: Bootloader for a mini-PLC with STM32F103VC

Post by BlackBrix » Tue Dec 26, 2017 4:47 pm

thanks for lots of infos,
but again my question
so, can I omit the complete "BUTTON" and the "USB-DISC" -stuff ? (from the #defines)

another point:
do I have to define the crystal frequency if it is different from the default 8MHz ?
I can see that this is done here for a 12MHz crystal --> https://github.com/rogerclarkmelbourne/ ... are.c#L118
my crystal frequency is 16MHz
do I have to add another (different) PLL setup sequence then in "hardware.c" ?

BlackBrix
Posts: 31
Joined: Wed Dec 06, 2017 7:49 am

Re: Bootloader for a mini-PLC with STM32F103VC

Post by BlackBrix » Wed Dec 27, 2017 4:42 pm

BlackBrix wrote:
Tue Dec 26, 2017 4:47 pm
my crystal frequency is 16MHz
do I have to add another (different) PLL setup sequence then in "hardware.c" ?
would it be OK to write it like this (for 16MHz HSE) ?

Code: Select all

/* Configure PLL */
#if defined XTAL16M
    // 16 MHz crystal  (using the Bit 17 PLLXTPRE=1 => HSE clock divided by 2 before PLL entry)
    SET_REG(RCC_CFGR, GET_REG(RCC_CFGR) | 0x001F0400); /* pll=72Mhz(x9/2),APB1=36Mhz,AHB=72Mhz */
#elif defined XTAL12M  
   // 12 MHz crystal 
    SET_REG(RCC_CFGR, GET_REG(RCC_CFGR) | 0x00110400); /* pll=72Mhz(x6),APB1=36Mhz,AHB=72Mhz */  
#else
    // 8 MHz crystal default
    SET_REG(RCC_CFGR, GET_REG(RCC_CFGR) | 0x001D0400); /* pll=72Mhz(x9),APB1=36Mhz,AHB=72Mhz */
#endif
is 0x001F0400 correct ?

zmemw16
Posts: 1685
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: Bootloader for a mini-PLC with STM32F103VC

Post by zmemw16 » Thu Dec 28, 2017 12:22 am

if i had do this, i'd fire up cubemx, setup for the chip and set the crystal, generate as little code as possible.
examining the setup code should give you the info required,
of course some translation may well be required :lol:
srp

BlackBrix
Posts: 31
Joined: Wed Dec 06, 2017 7:49 am

Re: [solved] Bootloader for a mini-PLC with STM32F103VE w/ 16MHz crystal

Post by BlackBrix » Wed Jan 03, 2018 10:44 am

BlackBrix wrote:
Wed Dec 27, 2017 4:42 pm
BlackBrix wrote:
Tue Dec 26, 2017 4:47 pm
my crystal frequency is 16MHz
do I have to add another (different) PLL setup sequence then in "hardware.c" ?
would it be OK to write it like this (for 16MHz HSE) ?

Code: Select all

/* Configure PLL */
#if defined XTAL16M
    // 16 MHz crystal  (using the Bit 17 PLLXTPRE=1 => HSE clock divided by 2 before PLL entry)
    SET_REG(RCC_CFGR, GET_REG(RCC_CFGR) | 0x001F0400); /* pll=72Mhz(x9/2),APB1=36Mhz,AHB=72Mhz */
#elif defined XTAL12M  
   // 12 MHz crystal 
    SET_REG(RCC_CFGR, GET_REG(RCC_CFGR) | 0x00110400); /* pll=72Mhz(x6),APB1=36Mhz,AHB=72Mhz */  
#else
    // 8 MHz crystal default
    SET_REG(RCC_CFGR, GET_REG(RCC_CFGR) | 0x001D0400); /* pll=72Mhz(x9),APB1=36Mhz,AHB=72Mhz */
#endif
is 0x001F0400 correct ?


just to give a short feedback:
I tested that (changed code in "hardware.c") on a STM32F103VET6 @ 16MHz-crystal and it works.
(I cross-checked then with another (Chinese) Board with STM32F103VET6 @ 8MHz-crystal and this works as well)

I used the following configuration in 'config.h':

Code: Select all

// no HAS_MAPLE_HARDWARE ...
#define LED_BANK GPIOC
#define LED_PIN 9
#define LED_ON_STATE 0
// no BUTTON...-stuff
// no USB_DISC...-stuff
// 16MHz crystal:
#define XTAL16M 1

-------------------------


some other things & thoughts that came up when compiling the bootloader source:
(maybe it helps some other noobs like me)
  • the provided "Makefile" only* works on Linux (since there are used pure Linux shell commands like 'cp', 'rm' and linux-style path separators '/')
    the "Makefile" could be "cross-platformed" as done in other cores I know, see e.g. this example)
    If done so, it would be possible to use directly the provided "make_all.bat" with a pure windows toolchain like e.g. this one.
    *(unless you use some Linux 'shell emulation' environments like e.g. Cygwin or MinGW/MSYS that can run within Windows)
  • I did the compiling in a Linux (Ubuntu 16.04 LTS) environment using the provided "Makefile" (as it is).
    In my case it turned out that using the gcc-arm-none-eabi Vers. "4.9.3+svn231177-1" leaded to unusable/non-functional binaries,
    so in addition to Rogers Statement, I can not confirm that it compiles with 4.9.x,
    I only compiled & tested successfully with gcc-arm-none-eabi Versions: 4.8, 5.4, 6.0, 7.2
  • b.t.w.: you can use the "make_all.bat" under Linux as well, just insert at the first line of the file:
    #!/bin/bash
    then enable the file to be executable:
    chmod +x make_all.bat
    then just execute it with:
    ./make_all.bat

Post Reply