Running Chibios on custom board with stm32f103 MCU Topic is solved

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, utzig, tfAteba, barthess

User avatar
HDKLog
Posts: 41
Joined: Thu Aug 18, 2016 12:36 am
Been thanked: 2 times

Running Chibios on custom board with stm32f103 MCU

Postby HDKLog » Tue Mar 27, 2018 3:53 am

Hello.

I'm unable to run Chibios on custom board with STM32F103 MCU. The board has external 10 MHz high speed clock and according to the datasheet stm32f103 has maximum operating frequency 72 MHz which I was unable to achieve with 10 MHz so I decide to switch in to Internal 8 MHz clock. Here is my mcucfg.h settings:

Code: Select all

/*
 * HAL driver system settings.
 */
#define STM32_NO_INIT                       FALSE
#define STM32_HSI_ENABLED                   TRUE
#define STM32_LSI_ENABLED                   FALSE
#define STM32_HSE_ENABLED                   FALSE
#define STM32_LSE_ENABLED                   FALSE
#define STM32_SW                            STM32_SW_PLL
#define STM32_PLLSRC                        STM32_PLLSRC_HSI
#define STM32_PLLXTPRE                      STM32_PLLXTPRE_DIV1
#define STM32_PLLMUL_VALUE                  9
#define STM32_HPRE                          STM32_HPRE_DIV1
#define STM32_PPRE1                         STM32_PPRE1_DIV2
#define STM32_PPRE2                         STM32_PPRE2_DIV2
#define STM32_ADCPRE                        STM32_ADCPRE_DIV4
#define STM32_USB_CLOCK_REQUIRED            TRUE
#define STM32_USBPRE                        STM32_USBPRE_DIV1
#define STM32_MCOSEL                        STM32_MCOSEL_NOCLOCK
#define STM32_RTCSEL                        STM32_RTCSEL_NOCLOCK
#define STM32_PVD_ENABLE                    FALSE
#define STM32_PLS                           STM32_PLS_LEV0


every time when I run debug in ChibiStudio it get stuck and when I suspend debug session it stops on "ST_ENABLE_CLOCK()" (in disassembly window) on sdInit() (in hal.c). Any idea what can be wrong?

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Running Chibios on custom board with stm32f103 MCU

Postby Giovanni » Tue Mar 27, 2018 7:36 am

Hi,

this is what is used by the Nucleo64 demo:

Code: Select all

#define STM32_NO_INIT                       FALSE
#define STM32_HSI_ENABLED                   TRUE
#define STM32_LSI_ENABLED                   FALSE
#define STM32_HSE_ENABLED                   FALSE
#define STM32_LSE_ENABLED                   FALSE
#define STM32_SW                            STM32_SW_PLL
#define STM32_PLLSRC                        STM32_PLLSRC_HSI
#define STM32_PLLXTPRE                      STM32_PLLXTPRE_DIV1
#define STM32_PLLMUL_VALUE                  12
#define STM32_HPRE                          STM32_HPRE_DIV1
#define STM32_PPRE1                         STM32_PPRE1_DIV2
#define STM32_PPRE2                         STM32_PPRE2_DIV2
#define STM32_ADCPRE                        STM32_ADCPRE_DIV4
#define STM32_USB_CLOCK_REQUIRED            TRUE
#define STM32_USBPRE                        STM32_USBPRE_DIV1
#define STM32_MCOSEL                        STM32_MCOSEL_NOCLOCK
#define STM32_RTCSEL                        STM32_RTCSEL_NOCLOCK
#define STM32_PVD_ENABLE                    FALSE
#define STM32_PLS                           STM32_PLS_LEV0


Giovanni

User avatar
HDKLog
Posts: 41
Joined: Thu Aug 18, 2016 12:36 am
Been thanked: 2 times

Re: Running Chibios on custom board with stm32f103 MCU

Postby HDKLog » Tue Mar 27, 2018 7:38 am

Thank you for reply Giovanni, I tried it... behave the same. By reading some articles I realize that Internal high speed clock somehow is divided by 2 so PLL input is 4 MHz not 8. I changed my mcuconfig but it do the same.

Code: Select all

/*
 * HAL driver system settings.
 */
#define STM32_NO_INIT                       FALSE
#define STM32_HSI_ENABLED                   TRUE
#define STM32_LSI_ENABLED                   FALSE
#define STM32_HSE_ENABLED                   FALSE
#define STM32_LSE_ENABLED                   FALSE
#define STM32_SW                            STM32_SW_PLL
#define STM32_PLLSRC                        STM32_PLLSRC_HSI
#define STM32_PLLXTPRE                      STM32_PLLXTPRE_DIV1
#define STM32_PLLMUL_VALUE                  12
#define STM32_HPRE                          STM32_HPRE_DIV1
#define STM32_PPRE1                         STM32_PPRE1_DIV2
#define STM32_PPRE2                         STM32_PPRE2_DIV1
#define STM32_ADCPRE                        STM32_ADCPRE_DIV4
#define STM32_USB_CLOCK_REQUIRED            TRUE
#define STM32_USBPRE                        STM32_USBPRE_DIV1
#define STM32_MCOSEL                        STM32_MCOSEL_NOCLOCK
#define STM32_RTCSEL                        STM32_RTCSEL_NOCLOCK
#define STM32_PVD_ENABLE                    FALSE
#define STM32_PLS                           STM32_PLS_LEV0


here is Board schematics maybe there is something wrong?
viber image.jpg

User avatar
HDKLog
Posts: 41
Joined: Thu Aug 18, 2016 12:36 am
Been thanked: 2 times

Re: Running Chibios on custom board with stm32f103 MCU

Postby HDKLog » Thu Mar 29, 2018 7:09 pm

I replaced 10 MHz clock on 8 MHz and nothing changed. Board is similar to OLIMEX P103 but without external low speed oscillator, in board settings I have:

Code: Select all

#define STM32_LSECLK            0
#define STM32_HSECLK            8000000


and in mcuconf.h

Code: Select all

*
 * HAL driver system settings.
 */
#define STM32_NO_INIT                       FALSE
#define STM32_HSI_ENABLED                   TRUE
#define STM32_LSI_ENABLED                   FALSE
#define STM32_HSE_ENABLED                   TRUE
#define STM32_LSE_ENABLED                   FALSE
#define STM32_SW                            STM32_SW_PLL
#define STM32_PLLSRC                        STM32_PLLSRC_HSE
#define STM32_PLLXTPRE                      STM32_PLLXTPRE_DIV1
#define STM32_PLLMUL_VALUE                  9
#define STM32_HPRE                          STM32_HPRE_DIV1
#define STM32_PPRE1                         STM32_PPRE1_DIV2
#define STM32_PPRE2                         STM32_PPRE2_DIV1
#define STM32_ADCPRE                        STM32_ADCPRE_DIV6
#define STM32_USB_CLOCK_REQUIRED            TRUE
#define STM32_USBPRE                        STM32_USBPRE_DIV1P5
#define STM32_MCOSEL                        STM32_MCOSEL_NOCLOCK
#define STM32_RTCSEL                        STM32_RTCSEL_NOCLOCK
#define STM32_PVD_ENABLE                    FALSE
#define STM32_PLS                           STM32_PLS_LEV0


when I run debug session it doesn't reach first hard breakpoint in main and when I suspend it it stop on ST_ENABLE_CLOCK(). Anyone have any Idea whats going wrong? :|

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Running Chibios on custom board with stm32f103 MCU

Postby Giovanni » Thu Mar 29, 2018 7:13 pm

Try disabling all drivers and see if it starts, after that enable drivers one at time.

Giovanni

User avatar
HDKLog
Posts: 41
Joined: Thu Aug 18, 2016 12:36 am
Been thanked: 2 times

Re: Running Chibios on custom board with stm32f103 MCU

Postby HDKLog » Thu Mar 29, 2018 8:13 pm

Thank you for quick reply Giovanni.

I tried to disable all drivers even PAL driver but no results. I have 2 boards and both wont work. I don't know what to check now...

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Running Chibios on custom board with stm32f103 MCU

Postby Giovanni » Thu Mar 29, 2018 8:16 pm

I don't know, the STM32 should be able to start even alone, maybe it is simply defective.

Giovanni

User avatar
HDKLog
Posts: 41
Joined: Thu Aug 18, 2016 12:36 am
Been thanked: 2 times

Re: Running Chibios on custom board with stm32f103 MCU  Topic is solved

Postby HDKLog » Sat Mar 31, 2018 12:20 am

I replaced my MCU to stm32F103 from STLink part of NUCLEO board and there was no difference. Then I started to search problems in manuals and found there description of flash locking issue. After that I decide to check connection with MCU through OpenOCD. I tried to press and hold reset button then execute reset halt command. then release reset button and as expected, the output of OpenOCD was:

Code: Select all

timed out while waiting for target halted
TARGET: stm32f1x.cpu - Not halted
in procedure 'reset'
in procedure 'ocd_bouncer'


and after release of reset button

Code: Select all

target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08000160 msp: 0x20004000


meaning that MCU functioning properly. I tried to execute unlock command stm32f1x unlock 0
and output was:

Code: Select all

device id = 0x10006412
flash size = 32kbytes
stm32x unlocked.
INFO: a reset or power cycle is required for the new settings to take effect.


then I executed reset halt and reset run commands and was able to flash and debug code in ChibiStudio. Although AC6 IDE from STM community reports this problem with message like "Write protection error detected, check RDP and WRP" but ChibiStudio Does not...
Anyway thank you for your attention Giovanni.

Best regards,
Harry.


Return to “General Support”

Who is online

Users browsing this forum: No registered users and 15 guests