Page 2 of 3

Re: STM32F30x advanced timer center aligned PWM

Posted: Sun Dec 29, 2013 10:31 pm
by Giovanni
The above code is not equivalent, the former takes a pointer to the header of the list, the latter takes a pointer to the next element in the list.

The error may disappear but is the functionality the same?

Giovanni

Re: STM32F30x advanced timer center aligned PWM

Posted: Mon Dec 30, 2013 11:40 am
by tecnologic
Hi,

that was my problem to but i do not know an equivalent for that which suppresses the error. on the left side there is the type virtual_timer_t* and on the right side u have (void*) so i thought what is ment. My thought was the address of the head of the list and this is the first element of the structure. but as u say this is not the same cause i have taken the value of the head of the list not the address. but in general typing this is no good style i think. cause the data behind the head of the list is nothing like virtual_timer_t.

with this in mind this way is suitable:

Code: Select all

vtp->vt_next->vt_prev = (virtual_timer_t*)((void*)&ch.vtlist


this should lead to the same as the original one and suppress the error from g++.

Greets

Tec

PS:

this change made my Code run with 3.0. my first solution ended in an endless loop in the idle thead.

PSS:
https://bitbucket.org/Tecnologic/chibios-rt/commits/all
Here are my final changes to the hal an chvt. if it is easier to see there.

Re: STM32F30x advanced timer center aligned PWM

Posted: Mon Dec 30, 2013 12:12 pm
by Giovanni
I fixed the problem with macros and modified the cast to (virtual_timer_t *) but without the double cast, GCC does not complain about it.

Giovanni

Re: STM32F30x advanced timer center aligned PWM

Posted: Mon Dec 30, 2013 4:31 pm
by tecnologic
ok i tried this without double cast and everything was fine. Dont know y my first try was not succesesful.

Re: STM32F30x advanced timer center aligned PWM

Posted: Wed Mar 12, 2014 11:40 am
by tecnologic
Hi folks,

i found an other problem with my 144MHz clock config for timer 1/8. in hal_lld.h of STM32F30x there is an error i think.

Code: Select all

#define STM32_TIM1SW_MASK       (1 << 8)    /**< TIM1 clock source mask.   */
#define STM32_TIM1SW_PCLK2      (0 << 8)    /**< TIM1 clock is PCLK2.      */
#define STM32_TIM1SW_PLLX2      (1 << 10)   /**< TIM1 clock is PLL*2.      */
#define STM32_TIM8SW_MASK       (1 << 10)   /**< TIM8 clock source mask.   */
#define STM32_TIM8SW_PCLK2      (0 << 10)   /**< TIM8 clock is PCLK2.      */
#define STM32_TIM8SW_PLLX2      (1 << 10)   /**< TIM8 clock is PLL*2.      */


should be according to RM00316

Bit 9 TIM8SW Timer8 clock source selection
Set and reset by software to select TIM8 clock source.
The bit is writable only when the following conditions occur: clock system = PLL, and AHB
and APB2 subsystem clock not divided respect the clock system.
The bit is reset by hardware when exiting from the previous condition (user must set the bit
again in case of a new switch is required)
0: PCLK2 clock (doubled frequency when prescaled) (default)
1: PLL vco output (running up to 144 MHz)
Bit 8 TIM1SW Timer1 clock source selection
Set and reset by software to select TIM1 clock source.
The bit is writable only when the following conditions occur: clock system = PLL, and AHB
and APB2 subsystem clock not divided respect the clock system.
The bit is reset by hardware when exiting from the previous condition (user must set the bit
again in case of a new switch is required)
0: PCLK2 clock (doubled frequency when prescaled) (default)
1: PLL vco output (running up to 144 MHz)

Code: Select all

#define STM32_TIM1SW_MASK       (1 << 8)    /**< TIM1 clock source mask.   */
#define STM32_TIM1SW_PCLK2      (0 << 8)    /**< TIM1 clock is PCLK2.      */
#define STM32_TIM1SW_PLLX2      (1 << 8)   /**< TIM1 clock is PLL*2.      */
#define STM32_TIM8SW_MASK       (1 << 9)   /**< TIM8 clock source mask.   */
#define STM32_TIM8SW_PCLK2      (0 << 9)   /**< TIM8 clock is PCLK2.      */
#define STM32_TIM8SW_PLLX2      (1 << 9)   /**< TIM8 clock is PLL*2.      */


if i'am right, could this be patched in v3 hal please?

Thanks

Tec

Re: STM32F30x advanced timer center aligned PWM

Posted: Wed Mar 12, 2014 1:46 pm
by Giovanni
Hi,

This is a bug so it will be fixed in 2.6.4 too. Adding to the TODO list.

Giovanni

Re: [TODO] STM32F30x advanced timer center aligned PWM

Posted: Wed Mar 12, 2014 4:04 pm
by tecnologic
glad i could help,

thanks Giovanni.

Re: [TODO] STM32F30x advanced timer center aligned PWM

Posted: Thu Mar 13, 2014 10:28 am
by tecnologic
Hi all,

this seems not to be the only problem. With the corrections above i get only 16kHz PWM meaning 72MHz feed into TIM1 but may be i'am just missing some configuration.
i attached my config below. the reasonable parts are:

Code: Select all

_pwmcfg({
            STM32_TIM1CLK,   // use PWM system clock
            (pwmcnt_t)(STM32_TIM1CLK/(u32Freq*2)),  //use double freq due to center aligned PWM
            NULL,
            {
             {PWM_OUTPUT_ACTIVE_HIGH | PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH, NULL},
             {PWM_OUTPUT_ACTIVE_HIGH | PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH, NULL},
             {PWM_OUTPUT_ACTIVE_HIGH | PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH, NULL},
             {PWM_OUTPUT_DISABLED, NULL}
            },
            /*
             * CR1 Register
             *
             * activate center aligned pwm
             */
            STM32_TIM_CR1_CMS(1),
            /*
             * CR2 Register
             *
             * Use Update events as Triger Output 1
             * Use CC4 Events as Trigger Output 2
             *
             */
            STM32_TIM_CR2_MMS(2) | STM32_TIM_CR2_MMS2(7),
            /*
             * Break and Deadtime Register
             *
             * Deadtime set in multiples of Timer CLK
             */
            STM32_TIM_BDTR_DTG((uint32_t)(fDeadTime * (float)STM32_TIM1CLK)),
            /*
             * no extra interrupts enabled
             */
            0})

STM32_TIM1CLK is 144MHz so the internals of Chibios are thinking it right. and the PWMD1->clock also is 144MHz .

the Clock tree config is

Code: Select all


/*
 * HAL driver system settings.
 */
#define STM32_NO_INIT                       FALSE
#define STM32_PVD_ENABLE                    FALSE
#define STM32_PLS                           STM32_PLS_LEV0
#define STM32_HSI_ENABLED                   TRUE
#define STM32_LSI_ENABLED                   TRUE
#define STM32_HSE_ENABLED                   TRUE
#define STM32_LSE_ENABLED                   FALSE
#define STM32_SW                            STM32_SW_PLL
#define STM32_PLLSRC                        STM32_PLLSRC_HSE
#define STM32_PREDIV_VALUE                  1
#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_MCOSEL                        STM32_MCOSEL_NOCLOCK
#define STM32_ADC12PRES                     STM32_ADC12PRES_DIV1
#define STM32_ADC34PRES                     STM32_ADC34PRES_DIV1
#define STM32_USART1SW                      STM32_USART1SW_PCLK
#define STM32_USART2SW                      STM32_USART2SW_PCLK
#define STM32_USART3SW                      STM32_USART3SW_PCLK
#define STM32_UART4SW                       STM32_UART4SW_PCLK
#define STM32_UART5SW                       STM32_UART5SW_PCLK
#define STM32_I2C1SW                        STM32_I2C1SW_SYSCLK
#define STM32_I2C2SW                        STM32_I2C2SW_SYSCLK
#define STM32_TIM1SW                        STM32_TIM1SW_PLLX2
#define STM32_TIM8SW                        STM32_TIM8SW_PLLX2
#define STM32_RTCSEL                        STM32_RTCSEL_LSI
#define STM32_USB_CLOCK_REQUIRED            TRUE
#define STM32_USBPRE                        STM32_USBPRE_DIV1P5

/*
 * PWM driver system settings.
 */
#define STM32_PWM_USE_ADVANCED              TRUE
#define STM32_PWM_USE_TIM1                  TRUE
#define STM32_PWM_USE_TIM2                  FALSE
#define STM32_PWM_USE_TIM3                  FALSE
#define STM32_PWM_USE_TIM4                  FALSE
#define STM32_PWM_USE_TIM8                  FALSE
#define STM32_PWM_TIM1_IRQ_PRIORITY         7
#define STM32_PWM_TIM2_IRQ_PRIORITY         7
#define STM32_PWM_TIM3_IRQ_PRIORITY         7
#define STM32_PWM_TIM4_IRQ_PRIORITY         7
#define STM32_PWM_TIM8_IRQ_PRIORITY         7




does any body have a clue to what i'am doing wrong?

Thanks

Tec

Re: [TODO] STM32F30x advanced timer center aligned PWM

Posted: Tue Mar 18, 2014 10:38 am
by Giovanni
I fixed the bug in repository (#473).

Looking at your configuration structure I noticed you added a CR1 initialization field not present in the current codebase, are you using a customization there? the center aligned mode is not yet supported in the distributed code.

Giovanni

Re: [DONE] STM32F30x advanced timer center aligned PWM

Posted: Tue Mar 18, 2014 11:45 am
by tecnologic
Hi,

Anyone an Idea? Does nobody else use the 144MHz Clock for TIM1 or TIM8?

I went through the hal_lld.h of the F303 and found several copy and paste issues:

ADC34 Prescaler was shifted by 4 as ADC12 Prescaler but should be shifted by 9 regarding to RM316
see:

Code: Select all

#define STM32_ADC34PRES_MASK    (31 << 9)   /**< ADC34 clock source mask.   */
#define STM32_ADC34PRES_NOCLOCK (0 << 9)    /**< ADC34 clock is disabled.   */
#define STM32_ADC34PRES_DIV1    (16 << 9)   /**< ADC34 clock is PLL/1.      */
#define STM32_ADC34PRES_DIV2    (17 << 9)   /**< ADC34 clock is PLL/2.      */
#define STM32_ADC34PRES_DIV4    (18 << 9)   /**< ADC34 clock is PLL/4.      */
#define STM32_ADC34PRES_DIV6    (19 << 9)   /**< ADC34 clock is PLL/6.      */
#define STM32_ADC34PRES_DIV8    (20 << 9)   /**< ADC34 clock is PLL/8.      */
#define STM32_ADC34PRES_DIV10   (21 << 9)   /**< ADC34 clock is PLL/10.     */
#define STM32_ADC34PRES_DIV12   (22 << 9)   /**< ADC34 clock is PLL/12.     */
#define STM32_ADC34PRES_DIV16   (23 << 9)   /**< ADC34 clock is PLL/16.     */
#define STM32_ADC34PRES_DIV32   (24 << 9)   /**< ADC34 clock is PLL/32.     */
#define STM32_ADC34PRES_DIV64   (25 << 9)   /**< ADC34 clock is PLL/64.     */
#define STM32_ADC34PRES_DIV128  (26 << 9)   /**< ADC34 clock is PLL/128.    */
#define STM32_ADC34PRES_DIV256  (27 << 9)   /**< ADC34 clock is PLL/256.    */



Regards

Tec