[SOLVED] the best way to use 16MHz crystal (given board [STM32F1]) ?

If you made your own board, post here, unless you built a Maple or Maple mini clone etc
User avatar
mrburnette
Posts: 2045
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: [STM32F1] the best way to use 16MHz crystal (given board) ?

Post by mrburnette » Mon Jan 01, 2018 11:41 pm

BlackBrix wrote:
Mon Jan 01, 2018 9:10 pm
mrburnette wrote:Why should the core be changed for a one-off initiative ?
because the core could be executed on all extisting or future boards with 16MHz-crystal then.
<...>
there's done no overclocking, it is still all the same like on the 8MHz-crystal boards:
pll=72Mhz / APB1=36Mhz / AHB=72Mhz / USB=48MHz
touché on both!

However, our forum owner and master edit-meister, Roger Clark wrote this line less than 24 hours ago:
I know there are a stack of PRs that I have to process, but I've had a very busy end to 2017 with both work and home life which have to take priority.
It is absolutely prudent that all members understand that this forum is a private venture, not commercial, is sponsored and maintained essentially by one human being who does strive to "have a life" beyond the forum. IMO, requesting core changes should be minimized to fixes for faults and high-priority enhancements that benefit a large portion of the membership. Minimal changes that affect a small population of members need to be documented but can easily be managed off-line, parallel to the master github account. Or, create a parallel github branch and sync only as needed... I know several members have taken this approach.

Ray

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

Re: [STM32F1] the best way to use 16MHz crystal (given board) ?

Post by zmemw16 » Tue Jan 02, 2018 12:04 am

can we invert this and ask how to make it such it could be applied to any platform ?
externalize it from the core ?
could it made in such a way that the cores use c.f a linked library, built simply on the crystal frequency.

new year, new ideas, ok maybe :D

stephen

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

Re: [STM32F1] the best way to use 16MHz crystal (given board) ?

Post by BlackBrix » Wed Jan 03, 2018 9:52 am

mrburnette wrote:
Mon Jan 01, 2018 11:41 pm
It is absolutely prudent that all members understand that this forum is a private venture, not commercial, is sponsored and maintained essentially by one human being who does strive to "have a life" beyond the forum.
yeah,
I absolutely agree and understand that *thumbsup*
mrburnette wrote:
Mon Jan 01, 2018 11:41 pm
Or, create a parallel github branch and sync only as needed...
yes you're right, I did that already.
(although I do not (yet) have any knowledge at all about using git/github the right way :oops: )
.
.
zmemw16 wrote:can we invert this and ask how to make it such it could be applied to any platform ?
externalize it from the core ?
I second that,
that was also my original intention/wish (as you can see from my first post of this thread),
that would be the right way (not needing to touch the core) ...

User avatar
Pito
Posts: 1700
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: [STM32F1] the best way to use 16MHz crystal (given board) ?

Post by Pito » Wed Jan 03, 2018 10:52 am

that would be the right way (not needing to touch the core) ...
In the \STM32F1\variants\generic_stm32f103v\wirish\boards.cpp there is (line 129)

Code: Select all

    // Configure AHBx, APBx, etc. prescalers and the main PLL.
    wirish::priv::board_setup_clock_prescalers();
    rcc_configure_pll(&wirish::priv::w_board_pll_cfg);
What would happen if you added

Code: Select all

    // Configure AHBx, APBx, etc. prescalers and the main PLL.
    wirish::priv::board_setup_clock_prescalers();
    rcc_configure_pll(&wirish::priv::w_board_pll_cfg);
   // Pito: Added the 16MHz Xtal option
   #ifdef XTAL16M
    // in this case we additionally set the Bit 17 (PLLXTPRE=1)
    RCC_BASE->CFGR = cfgr | RCC_CFGR_PLLXTPRE;
   #endif
    
:?: :?:
Pukao Hats Cleaning Services Ltd.

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

Re: [STM32F1] the best way to use 16MHz crystal (given board) ?

Post by BlackBrix » Wed Jan 03, 2018 1:18 pm

aah, yes, this could work
I will check that out ...

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

Re: [STM32F1] the best way to use 16MHz crystal (given board) ?

Post by BlackBrix » Thu Jan 04, 2018 1:13 pm

Pito, I checked that and it works :D

[edit] there's only one additional line needed,
so the final solution is (in "..\STM32F1\variants\YOUR_BOARD\wirish\boards.cpp"):

Code: Select all

    // Configure AHBx, APBx, etc. prescalers and the main PLL.
    wirish::priv::board_setup_clock_prescalers();
    rcc_configure_pll(&wirish::priv::w_board_pll_cfg);
    
#ifdef XTAL16M
    // 16MHz crystal (HSE)
    // in this case we additionally set the Bit 17 (PLLXTPRE=1)  =>  then HSE clock is divided by 2 before PLL entry
    RCC_BASE->CFGR |= RCC_CFGR_PLLXTPRE;
#endif
    
the #define XTAL16M -statement can be put into "..\STM32F1\variants\YOUR_BOARD\board\board.h" then (if needed)

so we don't need to touch the core files, that's good

-----------

if the defined constant RCC_CFGR_PLLXTPRE is dot defined in your core or board (or future libmaple files) you may just use the following line instead:

Code: Select all

RCC_BASE->CFGR |= (1U << 17);
where 17 represents the bit responsible for the "HSE divider for PLL entry" within the register RCC_CFGR.
Last edited by BlackBrix on Thu Jan 04, 2018 1:55 pm, edited 3 times in total.

User avatar
Pito
Posts: 1700
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: [STM32F1] the best way to use 16MHz crystal (given board) ?

Post by Pito » Thu Jan 04, 2018 1:34 pm

uint32 cfgr = RCC_BASE->CFGR;
RCC_BASE->CFGR = cfgr | RCC_CFGR_PLLXTPRE;

Code: Select all

RCC_BASE->CFGR |=  RCC_CFGR_PLLXTPRE;
no additional line needed :?:
Last edited by Pito on Thu Jan 04, 2018 1:52 pm, edited 1 time in total.
Pukao Hats Cleaning Services Ltd.

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

Re: [STM32F1] the best way to use 16MHz crystal (given board) ?

Post by BlackBrix » Thu Jan 04, 2018 1:51 pm

yes, this works as well (but without space between '|' and '=' (was a typo in your post above)),
I edited my post above accordingly ... 8-)
Last edited by BlackBrix on Thu Jan 04, 2018 3:13 pm, edited 2 times in total.

User avatar
Pito
Posts: 1700
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: [STM32F1] the best way to use 16MHz crystal (given board) ?

Post by Pito » Thu Jan 04, 2018 1:55 pm

Now the next step is to make a decision tree for 8/10/12/16/20/25MHz Xtals (the prescaler on/off and PLL multiplier setting), add the Xtal Menu option, and you may issue an PR :)
Pukao Hats Cleaning Services Ltd.

Post Reply