STM32 SPL to CubeF4 conversion issues - Page 1
Forum section: electronics / general

author: tanffn
author_rank: Contributor
timestamp: March 27, 2015, 11:46:38 am
content: New to this group, warm Hello to everyone!I need to integrate an old code written using the Standard Peripheral Library to a new (big)project that's using CubeF4.As easy as it sounds I can't find any commonality between the libs..1. Is there any documentation to help with migration?2. Is there a way to access the "old" SPL function / easily make them live side by side?3. I can find implementation to basic functions, like:The following SPL function TIM_ARRPreloadConfig() configures TIM_CR1_ARPE bit in CR1 register.Yet I was unable to find where ARR is configured in the new HAL lib.What do you suggest, how should I attack this?(Please ignore if it’s an inappropriate offer, but) I am willing to pay for the conversion assistance.Below is a portion, there is also SPI and DMA init calls.Code:///wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww/// Init Timers for the DMA///-----------------------------------------------------------------TIM_TimeBaseInitTypeDef timerInitStructure;TIM_BDTRInitTypeDef timer_BDTRInitStruct;///wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww/// Setup TIM4 Timer as master clock which is used as clock source/// for timers TIM1, TIM2, TIM3, TIM5 & TIM8. TIM4@84MHz. In this/// way all DMA<->SPI's are in sync/// All DMA and SPI TIM's must have same ARR register value in order/// for them to be in sync.///wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwRCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); // enable TIM3TIM_TimeBaseStructInit(&timerInitStructure); // fill structure with default valuestimerInitStructure.TIM_Prescaler = (TIM_PRESCALER) - 0x0001; // set TIM1 counting prescaler to 1 (PSC register)timerInitStructure.TIM_Period = TIM4_PERIOD; // reload value set to 1 -> 21MHz clock (ARR register)TIM_TimeBaseInit(TIM4, &timerInitStructure); // Init timer with structureTIM_UpdateRequestConfig(TIM4, TIM_UpdateSource_Regular); // set update request source to generate interupt or DMA request (CR1->URS bit)TIM_ARRPreloadConfig(TIM4,ENABLE); // set auto-reload preload to enable (CR1->ARPE)TIM_SelectOutputTrigger(TIM4, TIM_TRGOSource_Update); // set master mode selection to update (CR2->MMS)TIM_GenerateEvent(TIM4, TIM_EventSource_Update); // set update generation (EGR->UG)TIM_Cmd(TIM4, ENABLE);///wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww/// Setup TIM2 as slave timer clocked by TIM4. TIM2 triggers DMA/// which transfers channel selection data through SPI3./// TIM2 CC4 with 4us is used for the CONV/// TIM2 CC4 with 4us is used as trigger for transmission of channel/// selection data with 50 us period///wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwRCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); // enable TIM2TIM_TimeBaseStructInit(&timerInitStructure);timerInitStructure.TIM_Prescaler = (TIM_PRESCALER) - 0x0001; // set TIM2 counting prescaler to 1 (PSC register)timerInitStructure.TIM_Period = TIM2_PERIOD; // 42MHz/1 = 42MHz -> count each 1/42MHz (ARR register)TIM_TimeBaseInit(TIM2, &timerInitStructure);TIM_SelectSlaveMode(TIM2,TIM_SlaveMode_External1); // Set slave mode to external clock mode TIM4 (SMCR->SMS)TIM_SelectInputTrigger(TIM2,TIM_TS_ITR3); // Set internal triger to TIM4 (SMCR->TS)TIM_UpdateRequestConfig(TIM2, TIM_UpdateSource_Regular); // set update request source to generate interupt or DMA request (CR1->URS bit)TIM_ARRPreloadConfig(TIM2,ENABLE); // set auto-reload preload to enable (CR1->ARPE)TIM_SelectOutputTrigger(TIM2, TIM_TRGOSource_OC4Ref); // trigger output (TRGO) on CC4 (CR2->MMS)TIM_SetCompare4(TIM2,0x00A8); // duty cycle for the PWM set to 168 = 4us (CCR4 register)TIM_OC4PreloadConfig(TIM2,TIM_OCPreload_Enable); // enable OC4PE preload mode (CCMR2->OC4PE)TIM_ForcedOC4Config(TIM2,TIM_OCMode_PWM1); // set PWM1 mod (CCMR2->OC4M)TIM_OC4PolarityConfig(TIM2,TIM_OCPolarity_High); // set pulse polarity to active high (CCER->CC4P)TIM2->CCER |= (TIM_CCER_CC4E); // enable capture compare modeTIM_DMACmd(TIM2,TIM_DMA_CC4,ENABLE); // enable DMA request on capture compare CC4 event DIER->CC4DETIM_GenerateEvent(TIM2, TIM_EventSource_Update);TIM_Cmd(TIM2, ENABLE);...

author: AndyC_772
author_rank: Super Contributor
timestamp: March 27, 2015, 12:45:48 pm
content: I'm afraid you've found just what I did. Using ST's library doesn't save any time, effort or code compared to accessing the hardware registers directly, and the change between old and new libraries means you don't get a compatibility benefit either.My advice to you would be to step through your old code, make a note of what register accesses are happening inside the ST libs, and from that, work out how each peripheral you're using is really being configured. This is valuable knowledge in its own right.Then, write your new code to configure the corresponding peripherals in the same way, but without involving ST's libs (other than to define register bits and addresses in the header files). Take control yourself. You'll end up with code that's smaller, more efficient, and where you know exactly what it is (and isn't) doing.

author: tanffn
author_rank: Contributor
timestamp: March 27, 2015, 02:07:44 pm
content: Thank you Andy for the fast reply!Thats indid an option that I also considered (that or merging old and new libs).The main advantage of a lib, as I see it, is the readability and scalability ("DMA_Channel_3" instead of bit k in a reg).The HAL is .. Unnecessary but they did a nice integration with RTOS and other libs which make it easy to run forward with the actual coding.

author: Jeroen3
author_rank: Super Contributor
timestamp: March 27, 2015, 03:04:38 pm
content: The libraries serve as application example. However, simple use of peripherals can be achieved by using them so you will save a few hours (or days?) of code cleanup.Never expect libraries to be up/back-wards compatible unless the creators are bound to long term support contracts/licenses. For example, with a licensed ethernet stack you may expect api compatibility with newer versions. Or a migration assistance.Unfortunately the st libs are as-is in their "terms of use"....

author: tanffn
author_rank: Contributor
timestamp: March 27, 2015, 06:33:30 pm
content: Thats true Jeroen.. :/ but I want to freeze the lib ver and move forward.I think I will write a small app that will simply add SPL_ to all functions, stucks, macros, .. rename everything! (under SPL)Do you have a better idea? and do you know of such a tool

author: Jeroen3
author_rank: Super Contributor
timestamp: March 27, 2015, 07:33:09 pm
content: Notepad++ should be capable of search&replace in an entire folder.Be careful what you wish for.

author: dannyf
author_rank: Super Contributor
timestamp: March 27, 2015, 07:58:54 pm
content: QuoteNothing. Cube isn't for prime time.

author: tanffn
author_rank: Contributor
timestamp: March 27, 2015, 11:56:42 pm
content: Quote from: Jeroen3 on March 27, 2015, 07:33:09 pmYou're right but it needs to be smarter, I don't want manually select each name and Press Ctrl+HQuote from: dannyf on March 27, 2015, 07:58:54 pmBeen hearing that quite a bit.. yet the 3rd party integration they've done is nice..