Skip to main content
mtaisser9
Associate II
April 28, 2008
Question

TIM4 do not work in STM32F103V8T6

  • April 28, 2008
  • 12 replies
  • 2579 views
Posted on April 28, 2008 at 08:19

TIM4 do not work in STM32F103V8T6

    This topic has been closed for replies.

    12 replies

    mtaisser9
    mtaisser9Author
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 12:31

    hy!

    i know, my fault, i copied the wrong part of my code.

    I tried to initialize all 4 timers.

    1 - 3 worked fine, only 4th doesn't work.

    I took a look at the registers of TIM4 with the debugger when this line appears

    Code:

    TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);

    and nothing happens there.

    it looks like TIM4 isn't there!

    whole code is now:

    Code:

    // TIM4 clock enable 24MHz

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);

    // Time base configuration

    TIM_TimeBaseStructure.TIM_Period = TIM4_Freq_16kHz;

    TIM_TimeBaseStructure.TIM_Prescaler = 1;

    TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;

    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

    TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);

    TIM_ITConfig(TIM4,TIM_IT_Update, ENABLE);

    // Enable TIM4 global Interrupt

    NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQChannel;

    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC_InitStructure);

    // TIM enable counter

    TIM_Cmd(TIM4, ENABLE);

    smart
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 12:31

    Take a look at this line of your code

    NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQChannel;

    You have enabled the TIM3 interrupt not Timer 4

    This could be a problem....

    mtaisser9
    mtaisser9Author
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 12:31

    Hy!

    i try to use timer 4 (TIM4) in my project, but it doesn't work.

    Till now i tried all other timers (Timer1, Timer2&3) and they are working fine.

    I used the same initialization routines for Timer4 as for the others:

    Code:

    // TIM4 clock enable 24MHz

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);

    // Time base configuration

    TIM_TimeBaseStructure.TIM_Period = TIM4_Freq_16kHz;

    TIM_TimeBaseStructure.TIM_Prescaler = 1;

    TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;

    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

    TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);

    TIM_ITConfig(TIM4,TIM_IT_Update, ENABLE);

    // Enable TIM4 global Interrupt

    NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQChannel;

    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC_InitStructure);

    // TIM enable counter

    TIM_Cmd(TIM4, ENABLE);

    Timer 4 should be available in this device (described in the datasheet).

    µC: STM32F103V8

    IAR Embedded Workbench IDE

    JLINK for ARM processors

    Does anybody knows this issue or knows what happens with TIM4 in this device???

    mtaisser9
    mtaisser9Author
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 12:31

    i tried the example 8 with the ''GettingStarted'' workspace for IAR Workbench, and it works!

    i also checked the registers for TIM4 with debugger and the output pin channel1 of tim4.

    it worked fine.

    so i checked all my project settings, and did changes at the DEBUGGER -> DOWNLOAD -> Flash loader file.

    this was set to ''$TOOLKIT_DIR$\config\flashloader\ST\FlashSTM32F10x.d79'' manually.

    i changed it to the ''Default'' setting like in the working workspace (TIM4 example), and now i get crazy errors:

    Fri Apr 25 15:20:26 2008: DLL version: V3.80c, compiled Apr 9 2008 18:56:00

    Fri Apr 25 15:20:26 2008: Firmware: J-Link ARM V6 compiled Mar 3 2008 18:04:42

    Fri Apr 25 15:20:26 2008: JTAG speed is initially set to: 32 kHz

    Fri Apr 25 15:20:26 2008: TotalIRLen = 9, IRPrint = 0x0011

    Fri Apr 25 15:20:26 2008: Found Cortex-M3, Little endian.

    Fri Apr 25 15:20:26 2008: TPIU fitted.

    Fri Apr 25 15:20:26 2008: FPUnit: 6 code (BP) slots and 2 literal slots

    Fri Apr 25 15:20:26 2008: Hardware reset with strategy 1 was performed

    Fri Apr 25 15:20:26 2008: Initial reset was performed

    Fri Apr 25 15:20:26 2008: J-Link found 2 JTAG devices. ARM core Id: 3BA00477(Cortex M3), ARM core Id: 00000000(ARM9)

    Fri Apr 25 15:20:26 2008: Device at TAP0 selected

    Fri Apr 25 15:20:28 2008: 3518 bytes downloaded and verified (2.36 Kbytes/sec)

    Fri Apr 25 15:20:28 2008: Warning:

    Verify error at address 0x20000168, target byte: 0x00, byte in file: 0x09

    Fri Apr 25 15:20:28 2008: Warning:

    Verify error at address 0x20000169, target byte: 0x00, byte in file: 0x68

    Fri Apr 25 15:20:28 2008: Warning:

    Verify error at address 0x2000016A, target byte: 0x00, byte in file: 0x51

    Fri Apr 25 15:20:28 2008: Warning:

    Verify error at address 0x2000016B, target byte: 0x00, byte in file: 0xF0

    Fri Apr 25 15:20:28 2008: Warning:

    Verify error at address 0x2000016C, target byte: 0xBE, byte in file: 0x04

    Fri Apr 25 15:20:28 2008: Warning:

    Verify error at address 0x2000016D, target byte: 0x0A, byte in file: 0x01

    Fri Apr 25 15:20:28 2008: Warning:

    Verify error at address 0x2000016E, target byte: 0x00, byte in file: 0x01

    Fri Apr 25 15:20:28 2008: Warning:

    Verify error at address 0x2000016F, target byte: 0x00, byte in file: 0x60

    Fri Apr 25 15:20:28 2008: Warning:

    Verify error at address 0x20000170, target byte: 0x32, byte in file: 0x06

    Fri Apr 25 15:20:28 2008: Warning:

    Verify error at address 0x20000171, target byte: 0x0C, byte in file: 0x48

    Fri Apr 25 15:20:28 2008: Warning:

    Verify error at address 0x20000172, target byte: 0x00, byte in file: 0x06

    Fri Apr 25 15:20:28 2008: Warning:

    Verify error at address 0x20000173, target byte: 0x00, byte in file: 0x49

    Fri Apr 25 15:20:28 2008: Warning:

    Verify error at address 0x20000174, target byte: 0x04, byte in file: 0x09

    Fri Apr 25 15:20:28 2008: Warning:

    Verify error at address 0x20000175, target byte: 0x0A, byte in file: 0x68

    Fri Apr 25 15:20:28 2008: Warning:

    Verify error at address 0x20000176, target byte: 0x00, byte in file: 0x01

    Fri Apr 25 15:20:28 2008: Warning:

    Verify error at address 0x20000177, target byte: 0x00, byte in file: 0x22

    Fri Apr 25 15:20:28 2008: Warning:

    Verify error at address 0x20000178, target byte: 0xD6, byte in file: 0x91

    Fri Apr 25 15:20:28 2008: Warning:

    Verify error at address 0x20000179, target byte: 0x02, byte in file: 0x43

    Fri Apr 25 15:20:28 2008: Warning:

    Verify error at address 0x2000017A, target byte: 0x00, byte in file: 0x01

    Fri Apr 25 15:20:28 2008: Warning:

    Verify error at address 0x2000017B, target byte: 0x00, byte in file: 0x60

    Fri Apr 25 15:20:28 2008: Warning:

    Verify error at address 0x2000017C, target byte: 0x1F, byte in file: 0x24

    Fri Apr 25 15:20:28 2008: Warning:

    Verify error at address 0x2000017D, target byte: 0x0F, byte in file: 0x1D

    Fri Apr 25 15:20:28 2008: Warning:

    Verify error at address 0x2000017E, target byte: 0x00, byte in file: 0x3F

    Fri Apr 25 15:20:28 2008: Warning:

    Verify error at address 0x2000017F, target byte: 0x00, byte in file: 0x1D

    Fri Apr 25 15:20:28 2008: There were warnings during download of FLASH loader, see Log Window

    Fri Apr 25 15:20:29 2008: Failed to load flash loader: C:\Programme\IAR Systems\Embedded Workbench 4.0 Kickstart\arm\config\flashloader\ST\FlashSTM32F10x.d79

    When i try to change to the settings before, the same error occurs.

    i don't know what to do now.

    i tried 2 boards with my described processor type, and the IAR kickstart kit board, nothing helps!!!

    jilisegiar
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 12:31

    can you try the TIM example 8 from the ''ARM-based 32-bit MCU STM32F101xx and STM32F103xx firmware library''. It uses the TIM4 and it works fine.

    http://www.st.com/mcu/modules.php?name=mcu&file=familiesdocs&FAM=110#Firmware

    mtaisser9
    mtaisser9Author
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 12:31

    Hy!

    Today i did some other tests with my software.

    i took another (unflashed) board, and tried my software without enabling the ADC with DMA.

    the flashing and debugging with ''IAR workbench'' worked fine!

    i repeated that procedure several times without any problem.

    Than i tried to enable the ADC with DMA.

    The first programming (flashing) was done correctly and all works fine.

    but when i try to flash again the same software the described errors appear.

    What could be the problem???

    my ADC init routine:

    Code:

    void Analog_Init(void)

    {

    // Enable DMA clock

    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA, ENABLE);

    // Enable ADC1 and GPIOC clock

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_GPIOC, ENABLE);

    // DMA channel1 configuration ----------------------------------------------

    DMA_DeInit(DMA_Channel1);

    DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)ADC1_DR_Address;

    DMA_InitStructure.DMA_MemoryBaseAddr = (u32)ADC_ConvertedValueTab;

    DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;

    DMA_InitStructure.DMA_BufferSize = 6;

    DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;

    DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;

    DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;

    DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;

    DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;

    DMA_InitStructure.DMA_Priority = DMA_Priority_High;

    DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;

    DMA_Init(DMA_Channel1, &DMA_InitStructure);

    // Enable DMA Channel1

    DMA_Cmd(DMA_Channel1, ENABLE);

    // ADC1 configuration ------------------------------------------------------

    ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;

    ADC_InitStructure.ADC_ScanConvMode = ENABLE;

    ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;

    ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;

    ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

    ADC_InitStructure.ADC_NbrOfChannel = 6;

    ADC_Init(ADC1, &ADC_InitStructure);

    // ADC1 regular channels configuration

    ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime_239Cycles5);

    ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 2, ADC_SampleTime_239Cycles5);

    ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 3, ADC_SampleTime_239Cycles5);

    ADC_RegularChannelConfig(ADC1, ADC_Channel_13, 4, ADC_SampleTime_239Cycles5);

    ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 5, ADC_SampleTime_239Cycles5);

    ADC_RegularChannelConfig(ADC1, ADC_Channel_15, 6, ADC_SampleTime_239Cycles5);

    // Enable ADC1 DMA

    ADC_DMACmd(ADC1, ENABLE);

    // Enable ADC1

    ADC_Cmd(ADC1, ENABLE);

    // Enable ADC1 reset calibaration register

    ADC_ResetCalibration(ADC1);

    // Check the end of ADC1 reset calibration register

    while(ADC_GetResetCalibrationStatus(ADC1));

    // Start ADC1 calibaration

    ADC_StartCalibration(ADC1);

    // Check the end of ADC1 calibration

    while(ADC_GetCalibrationStatus(ADC1));

    // Start ADC1 Software Conversion

    ADC_SoftwareStartConvCmd(ADC1, ENABLE);

    }

    mtaisser9
    mtaisser9Author
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 12:31

    hy!

    in principle its the same code like in the ''getting started'' example, only with the Example 8 files included.

    with my company project i started also with the ''gettingStarted''.

    Following peripherals are in use:

    ADC with DMA

    I2C for Display

    I2C for Flash

    TIM1 to 3

    and some GPIO for keyboard etc.

    i recognized the first problems since i included the ADC with DMA!

    i don't know if this could be the problem

    jilisegiar
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 12:31

    Can you share your project

    mtaisser9
    mtaisser9Author
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 12:31

    Thanks, but it didn't work with this settings, because they are already set.

    i tried the ''software reset'' and it works!

    is it ok to set to ''software reset''?

    jilisegiar
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 12:31

    To avoid this problem try to reconfigure your project as in the attached image