Spark Logic

Custom STM32F103C8T6

STM32F103C8T6 LQFP48 Pinout
AS5048A TSSOP-14 Pinout

Hey guys!

I recently designed a custom STM32STM32Microcontrollers and processors…Map magic glue code, ethernet compiles, just WARNING: library LwIP claims to run on [ stm32 ] architecture(s) and may be incompatible with your current board which runs on [STM32]…View in hardware catalog board for an RS485 aplication. I was using an Atmega 168 before and I was having trouble with speed, so I decided it was time to move.
The board is simply a STM32F103C8T6STM32F103C8T6Microcontrollers and processors…e Sep 27, 2016 10:28 pm I know this is an old topic, but… I’m using blue pill board ( STM32F103C8T6 , version 3). With the current (modified) Adafruit library 0.96″ OLED display w…View in hardware catalog with an AS5048AAS5048ASensors, encoders and cameras…speed, so I decided it was time to move. The board is simply a STM32F103C8T6 with an AS5048A magnetic encoder and a SN65HVD78 transceiver. It reads the encoder via SPI and sends t…View in hardware catalog magnetic encoder and a SN65HVD78SN65HVD78Communications, navigation, interfaces and RFID… to move. The board is simply a STM32F103C8T6 with an AS5048A magnetic encoder and a SN65HVD78 transceiver. It reads the encoder via SPI and sends the information to a dynamixel s…View in hardware catalog transceiver. It reads the encoder via SPI and sends the information to a dynamixel servo network, using the dynamixel protocol. I have the SWD pins to program it.
As I already have the code for the arduino IDE so I was thinking what should I modify on my code to port it. Another question I have is how I set the clock on the microcontroller (on AVRAVRMicrocontrollers and processors…Arduino\libraries\U8glib\U8glib.cpp, C:\Program Files (x86)\Arduino\hardware\arduino\ avr \cores\arduino\HardwareSerial.h, C:\Program Files (x86)\Arduino/Blink3.ino, D:\Users\me\A…View in hardware catalog devices you use the memory fuses)? I’m using a 16Mhz crystal to reach the 72Mhz.
If you want, I can send the codes, the libs and the board schematic.
Here is a picture of the boards (I have two different models to fit in different places). I’m now soldering them and waiting for a few components to arrive.
Image
I would apreciate a lot if someone could help me here.
Thanks!

Replies20

Fri May 20, 2016 9:19 pm

Normally STM boards using 8MHz XTAL and a programmable PLL creates the 72MHz. There is a complex clock system compared with AVRAVRMicrocontrollers and processors…Arduino\libraries\U8glib\U8glib.cpp, C:\Program Files (x86)\Arduino\hardware\arduino\ avr \cores\arduino\HardwareSerial.h, C:\Program Files (x86)\Arduino/Blink3.ino, D:\Users\me\A…View in hardware catalog , that clocks different peripherals. Arduino core makes everything for setting up the clock, but as I said, it is better to use 8MHz crystal.
I suggest to read at least the first chapters of Geoffrey Brown’s book from here: http://www.cs.indiana.edu/~geobrown/book.pdf
It is very important to know something about MCU, everything will be more easy.
As for Arduino compatibility, I can say that most of the libraries not related with hardware directly, will work almost untouchable. Everything is here, Serial, I2C, SPI. Some code with external Interrupts and hardware timers it is possible to need some rework.

Sat May 21, 2016 12:28 pm

Slammer wrote:Normally STM boards using 8MHz XTAL and a programmable PLL creates the 72MHz. There is a complex clock system compared with AVRAVRMicrocontrollers and processors…Arduino\libraries\U8glib\U8glib.cpp, C:\Program Files (x86)\Arduino\hardware\arduino\ avr \cores\arduino\HardwareSerial.h, C:\Program Files (x86)\Arduino/Blink3.ino, D:\Users\me\A…View in hardware catalog , that clocks different peripherals. Arduino core makes everything for setting up the clock, but as I said, it is better to use 8MHz crystal.
I suggest to read at least the first chapters of Geoffrey Brown’s book from here: http://www.cs.indiana.edu/~geobrown/book.pdf
It is very important to know something about MCU, everything will be more easy.
As for Arduino compatibility, I can say that most of the libraries not related with hardware directly, will work almost untouchable. Everything is here, Serial, I2C, SPI. Some code with external Interrupts and hardware timers it is possible to need some rework.

Sat May 21, 2016 1:18 pm

In the case of F4xxx, it is quite explicit, the code is located in cores/maples/libmaple/rccF2.c :
        /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N */
#ifdef ARDUINO_STM32F4_NETDUINO2PLUS
int PLL_M = 25; // The NETDUINO has a 25MHz external oscillator
#else
int PLL_M = 8;
#endif
int PLL_N = 336;
/* SYSCLK = PLL_VCO / PLL_P */
int PLL_P = 2;

/* USB OTG FS, SDIO and RNG Clock =  PLL_VCO / PLLQ */
int PLL_Q = 7;

Sat May 21, 2016 1:52 pm

Like Martin says..

Its defined for each variant on the F1.

AFIK, no one else uses 16Mhz. Most boards use 8Mhz, though at least 1 STM32STM32Microcontrollers and processors…Map magic glue code, ethernet compiles, just WARNING: library LwIP claims to run on [ stm32 ] architecture(s) and may be incompatible with your current board which runs on [STM32]…View in hardware catalog board uses 12Mhz, and the GD32GD32Microcontrollers and processors…no bootloader and 120MHz clock. RogerClark Mon Feb 22, 2016 8:31 pm I tried to put a GD32 , taken from one board, onto a Maple mini, but my soldering was not good enough, and I ba…View in hardware catalog boards I have use 12Mhz.

Just to get the board working with your existing crystal, just hack the generic f130c board variant file
https://github.com/rogerclarkmelbourne/ … _setup.cpp

However I dont know how you setup a multipler of 16 to give you 72mhz. Youd need mult of 4.5

This may be possible, but I’m not sure

The values are defined in

https://github.com/rogerclarkmelbourne/ … ries/rcc.h

But you’d need to look in the main reference for the F103 (google RM0008) or click here http://www2.st.com/resource/en/referenc … 171190.pdf

And look to see if its supported and if so , how you set it.

But in the long term, get some 8Mhz crystals ;-)

Sat May 21, 2016 2:23 pm

@Dallasta
Open the MXBluePillF103C8MXBluePillF103C8Development and computing boards… get some 8Mhz crystals ;-)Wink Vassilis Sat May 21, 2016 2:23 pm @Dallasta Open the MXBluePillF103C8 .ioc file with STM32CubeMX and see how the 8 MHz clock configuration is set o…View in hardware catalog .ioc file with STM32CubeMX and see how the 8 MHz clock configuration is set on STM32F103C8STM32F103C8Microcontrollers and processors…017 8:28 am I am trying to get Phono’s library working on a MCP2551 and a blue pill ( STM32F103C8 ), I have it connected to a active CANBUS, and I have successfully received and s…View in hardware catalog MCU (Clock Configuration tab).

Sun May 22, 2016 6:15 am

There is a prescaler by 2 in front of PLL so you may divide a 16MHz crystal to get 8MHz and use the PLL setting as is. In order to switch the prescaler on:
PLLXTPRE: HSE divider for PLL entry
Set and cleared by software to divide HSE before PLL entry. This bit can be written only
when PLL is disabled.
0: HSE clock not divided
1: HSE clock divided by 2

Sun May 22, 2016 12:43 pm

Pito wrote:There is a prescaler by 2 in front of PLL so you may divide a 16MHz crystal to get 8MHz and use the PLL setting as is. In order to switch the prescaler on:
PLLXTPRE: HSE divider for PLL entry
Set and cleared by software to divide HSE before PLL entry. This bit can be written only
when PLL is disabled.
0: HSE clock not divided
1: HSE clock divided by 2

Sun May 22, 2016 1:23 pm

can you post a code snippet when you get it working using the libmaple based core , of what you did to make it work

Sun May 22, 2016 6:38 pm

Thanks for the help guys!
Now i’m really considering using 8Mhz crystals…
What’s the default configuration for the clock? I really dont want to hack things and hope for them to work. I dont have much time to finish this projetc (Brace yourselves, Robocup is coming!). If I use an 8Mhz crystal, the prescalers are already set to reach 72Mhz?

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 STM32F103STM32F103Microcontrollers and processors…19.html . ag123 Sat Apr 28, 2018 5:54 pm come to think of it blue pill / maple mini ( stm32f103 ) is an *ideal* keyboard controller, the scanning can be done with assistance of sh…View in hardware catalog to work out which bit enabled the DIV 2 on the input clock

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!

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!

Tue May 24, 2016 2:33 am

If you want to try to use your 16Mhz crystals

I think you’ll need to modify

STM32F1STM32F1Microcontrollers and processors…w I am not able to compile. Error message: “C:\arduino-1.6.12\hardware\Arduino_STM32\ STM32F1 \cores\maple/boards.h:39:25: fatal error: board/board.h: No such file or directory” I…View in hardware catalog \cores\MapleMapleDevelopment and computing boards…expensive short of buying in bulk. many resort to usb-serial converters. today comes leaflabs maple , stm32duino it is ‘disruptive’ in a similar light, user customizable usb is no…View in hardware catalog \libmaple\rcc_f1.c

Specifically

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;
}

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!

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 STM32F4STM32F4Microcontrollers and processors…uild.board' preference. Auto-set to: STM32F3_DISCOVERY_F3 Board Arduino_STM32-master: STM32F4 :discovery_f407 doesn't define a 'build.board' preference. Auto-set to: STM32F4_DISCO…View in hardware catalog (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.

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 AVRAVRMicrocontrollers and processors…Arduino\libraries\U8glib\U8glib.cpp, C:\Program Files (x86)\Arduino\hardware\arduino\ avr \cores\arduino\HardwareSerial.h, C:\Program Files (x86)\Arduino/Blink3.ino, D:\Users\me\A…View in hardware catalog 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!

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

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

Thu Jun 02, 2016 2:01 am

win 7 here. ST-LINKST-LINKModules, instruments and finished devices…ot add the serial usb device… suspect flashing failed…. Do I need to debrick it with st-link ? (which I don’t have lol) BennehBoy Mon Jan 23, 2017 8:11 pm NM managed to rescue it…View in hardware catalog shows up in device manager USB list as “Universal Serial Bus Devices \ STMIcroelectronics STLink dongle.”
Not in “Ports” serial ports

Thu Jun 02, 2016 2:06 am

stevech wrote:win 7 here. ST-LINKST-LINKModules, instruments and finished devices…ot add the serial usb device… suspect flashing failed…. Do I need to debrick it with st-link ? (which I don’t have lol) BennehBoy Mon Jan 23, 2017 8:11 pm NM managed to rescue it…View in hardware catalog shows up in device manager USB list as “Universal Serial Bus Devices \ STMIcroelectronics STLink dongle.”
Not in “Ports” serial ports

Post a reply

Optional · up to 10 MiB