Andy's Workshop Forums

General Category => stm32plus C++ library => Topic started by: pratipm on January 24, 2015, 07:32:45 am

Title: Support for STM32F103 Medium Density Performance Line
Post by: pratipm on January 24, 2015, 07:32:45 am
Is there any simple way I can use the library for STM32F103C8 (Medium density Performance line)? Boards with this cpu are available for about $5 on ebay, and I happen to have 2 of them.
Thanks.

-Pratip
Title: Re: Support for STM32F103 Medium Density Performance Line
Post by: Andy Brown on January 24, 2015, 07:38:29 am
Hi and welcome to the forum. It's quite likely that the library will work for you by using the f1hd configuration and simply avoiding the peripherals that you don't have.

The f1hd examples won't work "out of the box" because the linker script is designed for a 512Kb/64Kb configuration. You'd need to adjust it to match the 64Kb/20Kb configuration of your board. Your 72MHz clock matches the HD so the startup code that sets the clocks should work without changes.
Title: Re: Support for STM32F103 Medium Density Performance Line
Post by: pratipm on January 24, 2015, 07:58:21 am
Hi Andy,
Thanks for such a quick response. I'll give it a try right now!

-Pratip
Title: Re: Support for STM32F103 Medium Density Performance Line
Post by: Kenjutsu on April 15, 2015, 03:10:55 am
Quote from: pratipm on January 24, 2015, 07:58:21 am
Hi Andy,
Thanks for such a quick response. I'll give it a try right now!

-Pratip


Have you had any success in getting it to work with the STM32F103C8?
Title: Re: Support for STM32F103 Medium Density Performance Line
Post by: Andy Brown on April 16, 2015, 01:06:57 pm
Quote from: Kenjutsu on April 15, 2015, 03:10:55 am
Have you had any success in getting it to work with the STM32F103C8?


Hi, have you tried one of the examples on the F103C8? If you have tried and are having problems then please let me know and I'll try to help.
Title: Re: Support for STM32F103 Medium Density Performance Line
Post by: Kenjutsu on April 20, 2015, 07:25:55 am
Good day,

Not yet. I am still waiting for my board to arrive via eBay  ;)

I will provide feedback as soon as the board arrives, which will probable only be within the next month   :'(
Title: Re: Support for STM32F103 Medium Density Performance Line
Post by: Kenjutsu on June 02, 2015, 07:52:54 am
Well, my F103 board finally arrived  :) I got this one: STM32F103C8T6 ARM STM32 Minimum System Development Board Module (http://www.ebay.com/itm/181617112245?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT)

I followed the tutorial From zero to a C++ STM32 development environment (http://andybrown.me.uk/wk/2015/03/22/stm32dev-windows/) and completed Step 6, selecting the f1_hd_72_8 configuration for stm32plus and stm32plus-examples-blink. On my board the onboard LED is on PC13. So, just to get me started:

Thank you  ;)
Title: Re: Support for STM32F103 Medium Density Performance Line
Post by: Kenjutsu on June 03, 2015, 05:47:07 am
I saw this post here on the forum: Blink example on F103 custom board (http://www.andybrown.me.uk/forum/index.php/topic,8.0.html)

I modified Linker.ld as follows:
_estack = 0x20004FFF;    /* end of $(RAM_LENGTH) RAM */

_Min_Heap_Size = 0;      /* required amount of heap  */
_Min_Stack_Size = 0x200; /* required amount of stack */

MEMORY
{
  FLASH (rx)      : ORIGIN = 0x08000000, LENGTH = 128K
  RAM (xrw)       : ORIGIN = 0x20000000, LENGTH = 20K
}


and blink.cpp as follows:
      GpioD<DefaultDigitalOutputFeature<13> > pc;

      // loop forever switching it on and off with a 1 second
      // delay in between each cycle

      for(;;) {

        pc[13].set();
        MillisecondTimer::delay(1000);

        pc[13].reset();
        MillisecondTimer::delay(1000);


I compile and upload to the board, but still nothing happens. I also connected 4 LEDs to PA0, PA1, PA2 and PA3 and modified the code accordingly, but nothing happens  :(
Title: Re: Support for STM32F103 Medium Density Performance Line
Post by: Andy Brown on June 04, 2015, 05:44:32 am
Those linker settings look OK to me. Assuming you've connected the LED with a series resistor appropriate to the IO voltage on your board (probably 3.3V) then it should flash.

Can you run it in the Eclipse debugger and see what's going on?
Title: Re: Support for STM32F103 Medium Density Performance Line
Post by: yaqwsx on June 25, 2015, 02:14:05 pm
Hello,
I am also trying to use your great-looking library for STM32F103C8. I tried to use the F1_HD settings with linker script from VisualGDB. The blink example hangs in Default_Handler. It seems like no handlers were defined - when I look inside the g_pfnVectors, all vectors have defined Default_Handler.

Could you please take a look at it?
Title: Re: Support for STM32F103 Medium Density Performance Line
Post by: Andy Brown on June 25, 2015, 03:35:23 pm
Quote from: yaqwsx on June 25, 2015, 02:14:05 pm
Hello,
I am also trying to use your great-looking library for STM32F103C8. I tried to use the F1_HD settings with linker script from VisualGDB. The blink example hangs in Default_Handler. It seems like no handlers were defined - when I look inside the g_pfnVectors, all vectors have defined Default_Handler.

Could you please take a look at it?


I've ordered one of those incredibly cheap STM32F103C8 boards from ebay to have a look at but it's likely to be several weeks before it reaches me.

Can you break in Reset_Handler and single step to find out where it goes wrong? It's assembly language but is quite short. Basically it sets up some data then calls SystemInit and then main. It'll be particularly interesting to see if it gets past SystemInit where the clocks are initialised.
Title: Re: Support for STM32F103 Medium Density Performance Line
Post by: yaqwsx on June 25, 2015, 03:56:29 pm
Reset_Handler executes main. Even the pin is set high. However after several cycles in MillisecondTimer::delay the Default_Handler is triggered. It seems to me like the interrupt for SysTick was not defined.
Title: Re: Support for STM32F103 Medium Density Performance Line
Post by: Andy Brown on June 26, 2015, 12:45:28 am
The vector table in the MD series is shorter than the the HD but it is location-compatible right up to the end. Nevertheless, let's try replacing the startup assembly code with one designed for the MD line. Please replace the content of system/f1hd_72_8/Startup.asm with the attached file and let me know if it helps. I'm assuming you've already set the correct values for your flash and SRAM sizes in the linker script.
Title: Re: Support for STM32F103 Medium Density Performance Line
Post by: yaqwsx on June 26, 2015, 03:25:59 am
I looked closely to the startup code and the g_pfnVectors array is initialized properly (there are non-null address where should be), however all of them point to DefaultHandler.

There are also definitions for the aliases in the startup code like this:
void SysTick_Handler()            __attribute__ ((weak, alias ("Default_Handler")));

It seems like the aliases doesn't change when the library is linked.

To be clear: I am trying to use your library with GNU toolchain using Visual Studio and VisualGDB plugin, so I setup the project from scratch. It is possible, that I have ommited some steps necessary for the aliases to work. I attach the configuration of the project (the startup code and linker script are generated by VisualGDB).
Title: Re: Support for STM32F103 Medium Density Performance Line
Post by: Andy Brown on June 26, 2015, 09:37:30 am
Quote from: yaqwsx on June 26, 2015, 03:25:59 amTo be clear: I am trying to use your library with GNU toolchain using Visual Studio and VisualGDB plugin, so I setup the project from scratch. It is possible, that I have ommited some steps necessary for the aliases to work. I attach the configuration of the project (the startup code and linker script are generated by VisualGDB).


This is looking related to the change made in issue 19 (https://github.com/andysworkshop/stm32plus/issues/19) where the weak alias from SysTick_Handler to Default_Handler in Startup.asm was removed and now looks like this:


/*
* SysTick_Handler in stm32plus is now marked 'weak' so that compatibility with other
* frameworks is made possible.

  .weak  SysTick_Handler
  .thumb_set SysTick_Handler,Default_Handler
*/


The weak alias is now made to the stm32plus implementation so that users of an RTOS can integrate with the library and use the RTOS implementation of SysTick.

All other weak aliases of SysTick_Handler to Default_Handler must be removed. Unfortunately the Startup.asm I attached in my previous post did not have this weak alias commented out. If you could comment it out and ensure there are no more weak aliases for SysTick_Handler in your startup code then you should be OK.
Title: Re: Support for STM32F103 Medium Density Performance Line
Post by: yaqwsx on June 26, 2015, 01:27:45 pm
When I remove all weak alisese, I am not able to compile, since GCC doesn't compile the code.

Here's the auto-generated startup code:
/*
This file contains the entry point (Reset_Handler) of your firmware project.
The reset handled initializes the RAM and calls system library initializers as well as
the platform-specific initializer and the main() function.
*/

extern void *_estack;

#define NULL ((void *)0)

void Reset_Handler();
void Default_Handler();

#define BootRAM ((void *)0xF108F85F)

void NMI_Handler()                __attribute__ ((weak, alias ("Default_Handler")));
void HardFault_Handler()          __attribute__ ((weak, alias ("Default_Handler")));
void MemManage_Handler()          __attribute__ ((weak, alias ("Default_Handler")));
void BusFault_Handler()           __attribute__ ((weak, alias ("Default_Handler")));
void UsageFault_Handler()         __attribute__ ((weak, alias ("Default_Handler")));
void SVC_Handler()                __attribute__ ((weak, alias ("Default_Handler")));
void DebugMon_Handler()           __attribute__ ((weak, alias ("Default_Handler")));
void PendSV_Handler()             __attribute__ ((weak, alias ("Default_Handler")));
void SysTick_Handler()            __attribute__ ((weak, alias ("Default_Handler")));
void WWDG_IRQHandler()            __attribute__ ((weak, alias ("Default_Handler")));
void PVD_IRQHandler()             __attribute__ ((weak, alias ("Default_Handler")));
void TAMPER_IRQHandler()          __attribute__ ((weak, alias ("Default_Handler")));
void RTC_IRQHandler()             __attribute__ ((weak, alias ("Default_Handler")));
void FLASH_IRQHandler()           __attribute__ ((weak, alias ("Default_Handler")));
void RCC_IRQHandler()             __attribute__ ((weak, alias ("Default_Handler")));
void EXTI0_IRQHandler()           __attribute__ ((weak, alias ("Default_Handler")));
void EXTI1_IRQHandler()           __attribute__ ((weak, alias ("Default_Handler")));
void EXTI2_IRQHandler()           __attribute__ ((weak, alias ("Default_Handler")));
void EXTI3_IRQHandler()           __attribute__ ((weak, alias ("Default_Handler")));
void EXTI4_IRQHandler()           __attribute__ ((weak, alias ("Default_Handler")));
void DMA1_Channel1_IRQHandler()   __attribute__ ((weak, alias ("Default_Handler")));
void DMA1_Channel2_IRQHandler()   __attribute__ ((weak, alias ("Default_Handler")));
void DMA1_Channel3_IRQHandler()   __attribute__ ((weak, alias ("Default_Handler")));
void DMA1_Channel4_IRQHandler()   __attribute__ ((weak, alias ("Default_Handler")));
void DMA1_Channel5_IRQHandler()   __attribute__ ((weak, alias ("Default_Handler")));
void DMA1_Channel6_IRQHandler()   __attribute__ ((weak, alias ("Default_Handler")));
void DMA1_Channel7_IRQHandler()   __attribute__ ((weak, alias ("Default_Handler")));
void ADC1_2_IRQHandler()          __attribute__ ((weak, alias ("Default_Handler")));
void USB_HP_CAN1_TX_IRQHandler()  __attribute__ ((weak, alias ("Default_Handler")));
void USB_LP_CAN1_RX0_IRQHandler() __attribute__ ((weak, alias ("Default_Handler")));
void CAN1_RX1_IRQHandler()        __attribute__ ((weak, alias ("Default_Handler")));
void CAN1_SCE_IRQHandler()        __attribute__ ((weak, alias ("Default_Handler")));
void EXTI9_5_IRQHandler()         __attribute__ ((weak, alias ("Default_Handler")));
void TIM1_BRK_IRQHandler()        __attribute__ ((weak, alias ("Default_Handler")));
void TIM1_UP_IRQHandler()         __attribute__ ((weak, alias ("Default_Handler")));
void TIM1_TRG_COM_IRQHandler()    __attribute__ ((weak, alias ("Default_Handler")));
void TIM1_CC_IRQHandler()         __attribute__ ((weak, alias ("Default_Handler")));
void TIM2_IRQHandler()            __attribute__ ((weak, alias ("Default_Handler")));
void TIM3_IRQHandler()            __attribute__ ((weak, alias ("Default_Handler")));
void TIM4_IRQHandler()            __attribute__ ((weak, alias ("Default_Handler")));
void I2C1_EV_IRQHandler()         __attribute__ ((weak, alias ("Default_Handler")));
void I2C1_ER_IRQHandler()         __attribute__ ((weak, alias ("Default_Handler")));
void I2C2_EV_IRQHandler()         __attribute__ ((weak, alias ("Default_Handler")));
void I2C2_ER_IRQHandler()         __attribute__ ((weak, alias ("Default_Handler")));
void SPI1_IRQHandler()            __attribute__ ((weak, alias ("Default_Handler")));
void SPI2_IRQHandler()            __attribute__ ((weak, alias ("Default_Handler")));
void USART1_IRQHandler()          __attribute__ ((weak, alias ("Default_Handler")));
void USART2_IRQHandler()          __attribute__ ((weak, alias ("Default_Handler")));
void USART3_IRQHandler()          __attribute__ ((weak, alias ("Default_Handler")));
void EXTI15_10_IRQHandler()       __attribute__ ((weak, alias ("Default_Handler")));
void RTCAlarm_IRQHandler()        __attribute__ ((weak, alias ("Default_Handler")));
void USBWakeUp_IRQHandler()       __attribute__ ((weak, alias ("Default_Handler")));

void * g_pfnVectors[0x43] __attribute__ ((section (".isr_vector"))) =
{
&_estack,
&Reset_Handler,
&NMI_Handler,
&HardFault_Handler,
&MemManage_Handler,
&BusFault_Handler,
&UsageFault_Handler,
NULL,
NULL,
NULL,
NULL,
&SVC_Handler,
&DebugMon_Handler,
NULL,
&PendSV_Handler,
&SysTick_Handler,
&WWDG_IRQHandler,
&PVD_IRQHandler,
&TAMPER_IRQHandler,
&RTC_IRQHandler,
&FLASH_IRQHandler,
&RCC_IRQHandler,
&EXTI0_IRQHandler,
&EXTI1_IRQHandler,
&EXTI2_IRQHandler,
&EXTI3_IRQHandler,
&EXTI4_IRQHandler,
&DMA1_Channel1_IRQHandler,
&DMA1_Channel2_IRQHandler,
&DMA1_Channel3_IRQHandler,
&DMA1_Channel4_IRQHandler,
&DMA1_Channel5_IRQHandler,
&DMA1_Channel6_IRQHandler,
&DMA1_Channel7_IRQHandler,
&ADC1_2_IRQHandler,
&USB_HP_CAN1_TX_IRQHandler,
&USB_LP_CAN1_RX0_IRQHandler,
&CAN1_RX1_IRQHandler,
&CAN1_SCE_IRQHandler,
&EXTI9_5_IRQHandler,
&TIM1_BRK_IRQHandler,
&TIM1_UP_IRQHandler,
&TIM1_TRG_COM_IRQHandler,
&TIM1_CC_IRQHandler,
&TIM2_IRQHandler,
&TIM3_IRQHandler,
&TIM4_IRQHandler,
&I2C1_EV_IRQHandler,
&I2C1_ER_IRQHandler,
&I2C2_EV_IRQHandler,
&I2C2_ER_IRQHandler,
&SPI1_IRQHandler,
&SPI2_IRQHandler,
&USART1_IRQHandler,
&USART2_IRQHandler,
&USART3_IRQHandler,
&EXTI15_10_IRQHandler,
&RTCAlarm_IRQHandler,
&USBWakeUp_IRQHandler,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
BootRAM
};

void SystemInit();
void __libc_init_array();
void main();

extern void *_sidata, *_sdata, *_edata;
extern void *_sbss, *_ebss;

#include "stm32f10x.h"

void __attribute__((naked, noreturn)) Reset_Handler()
{
SCB->VTOR = (uint32_t)&g_pfnVectors;
//Normally the CPU should will setup the based on the value from the first entry in the vector table.
//If you encounter problems with accessing stack variables during initialization, ensure
//asm ("ldr sp, =_estack");

void **pSource, **pDest;
for (pSource = &_sidata, pDest = &_sdata; pDest != &_edata; pSource++, pDest++)
*pDest = *pSource;

for (pDest = &_sbss; pDest != &_ebss; pDest++)
*pDest = 0;

SystemInit();
__libc_init_array();
main();
for (;;) ;
}

void __attribute__((naked, noreturn)) Default_Handler()
{
//If we ended up here, an unexpected interrupt has happened (we did not defined the XXX_Handler function for it).
//See the definition of g_pfnVectors above for interrupt handler names.
for (;;) ;
}
Title: Re: Support for STM32F103 Medium Density Performance Line
Post by: Andy Brown on June 27, 2015, 03:44:31 am

void SysTick_Handler()            __attribute__ ((weak, alias ("Default_Handler")));


The above line is the problem. Since we are providing SysTick_Handler as a weak symbol ourselves, can you change that line to:


extern void SysTick_Handler();


I'm concerned that it's auto-generated. Is it a one-off auto-generation when the project is created or is there some trigger that will cause any changes that you make to be overwritten?
Title: Re: Support for STM32F103 Medium Density Performance Line
Post by: yaqwsx on June 27, 2015, 04:44:06 am
Thanks for clarification! The blink example now works as expected. Even the file is generated once (when the project is created), I would appreciate if the library provided a macro for optional weak symbols (something like DISABLE_WEAK_SYMBOLS). Do you think it would be possible to add it to the library?

I was also struggling with the SGI extension in form of slist. With the compiler on windows, I had to change includes in event.h to "#include "ext/slist"" and I also had to change namespace from std to __gnu_cxx. I have never worked with this extension before - is there a compiler flag which enables them or is this a "feature" of the compiler?

Thanks for your help.