Custom STM32F103C8T6

If you made your own board, post here, unless you built a Maple or Maple mini clone etc
User avatar
RogerClark
Posts: 5470
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Custom STM32F103C8T6

Postby RogerClark » Mon May 23, 2016 4:36 am

Yes

Use 8Mhz and you won't need to change any code.

I suspect to use 16Mhz, the change you would need to make is just 1 bit in one register, but I'd need to read the big manual on the STM32F103 to work out which bit enabled the DIV 2 on the input clock

stevech
Posts: 442
Joined: Thu Aug 27, 2015 6:32 am

Re: Custom STM32F103C8T6

Postby stevech » Mon May 23, 2016 10:57 pm

Signal32 wrote:This is great! Now I can use 3225 16Mhz crystals which are ~5 times cheaper than the 8Mhz ones. Thanks!
5x for a normal surface mount? Digikey pricing difference is 5 cents on an 85 cent part.

Signal32
Posts: 26
Joined: Sun May 08, 2016 12:19 am

Re: Custom STM32F103C8T6

Postby Signal32 » Mon May 23, 2016 11:55 pm

stevech wrote:
Signal32 wrote:This is great! Now I can use 3225 16Mhz crystals which are ~5 times cheaper than the 8Mhz ones. Thanks!
5x for a normal surface mount? Digikey pricing difference is 5 cents on an 85 cent part.


I was talking specifically about 3225(3.2mm x 2.5mm) crystals -- China pricing.
Digikey price difference in qty1 is only 2x, not 5x as with China pricing.

8MHz = 90c -- http://www.digikey.com/product-search/e ... ageSize=25
16Mhz = 46c -- http://www.digikey.com/product-search/e ... ageSize=25

Not to mention that you can get even smaller sizes for 16Mhz crystals (2016)

User avatar
RogerClark
Posts: 5470
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Custom STM32F103C8T6

Postby RogerClark » Tue May 24, 2016 2:33 am

If you want to try to use your 16Mhz crystals

I think you'll need to modify

STM32F1\cores\maple\libmaple\rcc_f1.c

Specifically

Code: Select all

void rcc_configure_pll(rcc_pll_cfg *pll_cfg) {
    stm32f1_rcc_pll_data *data = pll_cfg->data;
    rcc_pll_multiplier pll_mul = data->pll_mul;
    uint32 cfgr;
    /* Check that the PLL is disabled. */
    ASSERT_FAULT(!rcc_is_clk_on(RCC_CLK_PLL));

    cfgr = RCC_BASE->CFGR;
    cfgr &= ~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLMUL);
    cfgr |= pll_cfg->pllsrc | pll_mul;

    RCC_BASE->CFGR = cfgr;
}


Looking in the manual
http://www.st.com/content/ccc/resource/ ... 171190.pdf

on page 100

It looks like bit 17 is what you'd need to set in order to enabled the external prescaler "PLL XTPRE"

So you could change it in the boards_setup by changing the line

Code: Select all

        static stm32f1_rcc_pll_data pll_data = {BOARD_RCC_PLLMUL};


By OR'ing in

Code: Select all

(0x1 << 17)


e.g. I think like this

Code: Select all

static stm32f1_rcc_pll_data pll_data = {BOARD_RCC_PLLMUL | (0x1 << 17) };


But its difficult for me to test at the moment

User avatar
GrumpyOldPizza
Posts: 170
Joined: Fri Apr 15, 2016 4:15 pm
Location: Denver, CO

Re: Custom STM32F103C8T6

Postby GrumpyOldPizza » Wed Jun 01, 2016 12:06 pm

Signal32 wrote:
stevech wrote:
Signal32 wrote:This is great! Now I can use 3225 16Mhz crystals which are ~5 times cheaper than the 8Mhz ones. Thanks!
5x for a normal surface mount? Digikey pricing difference is 5 cents on an 85 cent part.


I was talking specifically about 3225(3.2mm x 2.5mm) crystals -- China pricing.
Digikey price difference in qty1 is only 2x, not 5x as with China pricing.

8MHz = 90c -- http://www.digikey.com/product-search/e ... ageSize=25
16Mhz = 46c -- http://www.digikey.com/product-search/e ... ageSize=25

Not to mention that you can get even smaller sizes for 16Mhz crystals (2016)


Interesting. Dragonfly is using a 16Mhz crystal over a 8MHz (https://www.tindie.com/products/onehors ... out-board/). I guess now I know why ;-)

Anyway, I ended up coding clock setup code that would compute the PLL values: stm32l4_system_configure(), https://github.com/GrumpyOldPizza/ardui ... 4_system.c.

The idea is pretty simple, but the limits and divisors are different for STM32F1 (this is for STM32L4). For latter one it's complicated by the fact that you may want to use MSI @ 48MHz if HSE is not present at all, which means your input clock (post M-divisor) needs to be 8MHz for consistency (16MHz HSE divided by 2, 48MHz MSI divided by 6). Here a quick snipped with the gist of it:

Code: Select all

   if (hseclk <= 48000000)
   {
       mout = hseclk / 8000000;
   }
   else
   {
       /* MSI with 48MHz */
       mout = 6;
   }
   
   fclk    = 8000000;
   fpllout = 0;
   nout    = 0;
   rout    = 0;
   
   for (r = 2; r <= 8; r += 2)
   {
       n = (sysclk * r) / fclk;
      
       fvco = fclk * n;
      
       if ((n >= 8) && (n <= 86) && (fvco <= 344000000) && (fvco >= 96000000))
       {
      fpll = fvco / r;
      
      /* Prefer lower N,R pairs for lower PLL current. */
      if (fpllout < fpll)
      {
          fpllout = fpll;
         
          nout = n;
          rout = r;
      }
       }
   }
   
   sysclk = fpllout;
    }


At the end mout, nout, rout should be valid for the selecting input "sysclk" (which then is subdivided into hclk, pclk1 & pclk2). Ah I should not forget to mention that I had also tried to autodetect the HSE value by comparing it to LSE (32.678kHz). Worked nicely, but was not needed for the task at hand ;-)

Anyway it seems to be easier to compute this on the fly than having to hardcode all sorts of values.

stevech
Posts: 442
Joined: Thu Aug 27, 2015 6:32 am

Re: Custom STM32F103C8T6

Postby stevech » Wed Jun 01, 2016 5:30 pm

Wouldn't a 16MHz crystal press the PLL stability and noise less than an 8MHz?

And, on the STM32F4 (and others?) the internal clock that runs at power up (HSI) and runs all the C startup code, is 16MHz. Switching to the HSE clock, stays at 16MHz until (or if) the PLL is used. Note that the C startup code at HSI speed has the problem that if you have a lot of BSS to be zero'd and/or a huge number of initialized variables (other than const), that all runs at HSI speed and can slow the startup process - if that's a factor. It is in one of my projects where the CPU has to get to the first line of code in main.c in < 10mSec.

I have an app on the '415 that runs at 16MHz for power up (hardware dictated) then on the PLL at 64MHz for most processing. When it's time to number-crunch, I switch to 168MHz for a few hundred mSec. Then back. For the switch, I reprogram some of the peripherals (debut UART, SPI) so they will stay at the same line speed no matter the speed switching to 168 then back to 64MHz.



Point being, the 8MHz crystal choice has other factors that may apply to some cases.

Dallasta
Posts: 6
Joined: Thu Mar 03, 2016 11:43 am

Re: Custom STM32F103C8T6

Postby Dallasta » Wed Jun 01, 2016 8:58 pm

Thank you guys for all the help, the 8mhz crystal seems to be working fine.
But I still have some doubts about the programming. Today I tried to make the serial work (uploading thru ST Link and no bootloader) and I was not able to do it. My hardware uses the USART2 and maybe that was the problem. Can someone help me?
Im still very newbie with ARM controllers, i have just dealed with AVR devices.
Also had a problem with the PWM, I dont know why, but it seems to just turn the pin to a normal IO pin, I could not set the frequency for it, hope someone have an idea avout this also.
Thanks!

User avatar
RogerClark
Posts: 5470
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Custom STM32F103C8T6

Postby RogerClark » Wed Jun 01, 2016 9:23 pm

I think STLink upload has USB serial enabled,

so Serial = USB Serial
Serial1 is Hardware serial 1
Serial2 is Hardware serial 2
etc

If you dont want USB serial, you will need to change boards.txt to remove the inline definitions for the USB serial stuff

or try uploading via Serial, as that upload mode does not have USB serial enabled

Dallasta
Posts: 6
Joined: Thu Mar 03, 2016 11:43 am

Re: Custom STM32F103C8T6

Postby Dallasta » Wed Jun 01, 2016 10:15 pm

RogerClark wrote:I think STLink upload has USB serial enabled,

so Serial = USB Serial
Serial1 is Hardware serial 1
Serial2 is Hardware serial 2
etc

If you dont want USB serial, you will need to change boards.txt to remove the inline definitions for the USB serial stuff

or try uploading via Serial, as that upload mode does not have USB serial enabled


Ooh, that helps a lot, I will try it tomorrow and bring the result here. I dont know if this information helps, but im using a discovery board to upload.
I have custom hardware, so its not so practical for me to upload via Serial, but i will try to change boards.txt and see if it works

stevech
Posts: 442
Joined: Thu Aug 27, 2015 6:32 am

Re: Custom STM32F103C8T6

Postby stevech » Thu Jun 02, 2016 2:01 am

win 7 here. ST-Link shows up in device manager USB list as "Universal Serial Bus Devices \ STMIcroelectronics STLink dongle."
Not in "Ports" serial ports


Return to “Custom design boards”

Who is online

Users browsing this forum: No registered users and 1 guest