[SOLVED] Cannot generate the PWM signal to the breakout board of the STM32F405 microcontroller
Posted: Tue Jun 13, 2017 8:06 pm
I need to generate the PWM signal to the pin IO1 (PB8, using TIMER10), and I have modify the main.c in the Eclipse project workspace on the Virtual Machine of Crazyflie like below. The clean and build doesn't give any error, but I cannot see any PWM output signal with the oscilloscope:
When I flash to the STM32F4 using CrazyRadio, the console is like this and it seems normal:
Is there anything wrong with the code? I did use quite the same code on STM32F4 Discovery for PWM generation and it worked, so I think the code is correct.
The only thing I'm doubted about is that there are some bug signs in some lines of code just like in the image attached. When I click in the bug, it says:
The .... is a name of a variable in #define part. I don't know there these bugs come from. I don't think it is because I haven't defined the path or the preprocessor for the project, because when I right click a variable/macro "See the Definition" or "See the Declaration", it shows up the source file where that variable/macro is defined.
I will appreciate any help. Please tell me if you see any problem.
Code: Select all
/* Personal configs */
#include "FreeRTOSConfig.h"
#include <stdint.h>
/* FreeRtos includes */
#include "FreeRTOS.h"
#include "task.h"
#include <stdint.h>
/* Project includes */
#include "config.h"
#include "platform.h"
#include "system.h"
#include "usec_time.h"
#include "led.h"
/* ST includes */
#include "stm32f4xx.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_tim.h"
/*Predefined macros*/
#define IR_TX_CARRIER_FREQ 56000
#define IR_TX_CARRIER_PWM_PERIOD (SystemCoreClock/IR_TX_CARRIER_FREQ)
#define IR_TX_DELAY_PRESCALER (84-1)
#define ENABLE 1
#define IR_TX_CARRIER_TIMER TIM10
#define IR_TX_CARRIER_TIMER_RCC RCC_APB2Periph_TIM10
#define IR_TX_CARRIER_TIMER_CH_Init TIM_OC1Init
#define IR_TX_CARRIER_TIMER_CH_PreloadConfig TIM_OC1PreloadConfig
#define IR_TX_CARRIER_TIMER_CH_SetCompare TIM_SetCompare1
#define IR_TX_CARRIER_RCC RCC_AHB1Periph_GPIOB
#define IR_TX_CARRIER_PORT GPIOB
#define IR_TX_CARRIER_PIN GPIO_Pin_8
void irTxInit(void);
int main()
{
//Initialize the platform.
platformInit();
//Launch the system task that will initialize and start everything
systemLaunch();
//Start the FreeRTOS scheduler
vTaskStartScheduler();
//PWM
irTxInit();
TIM10->CCR1 = 50*(65535/100);
GPIO_SetBits(GPIOB,GPIO_Pin_5);
//TODO: Move to platform launch failed
ledInit();
ledSet(0, 1);
ledSet(1, 1);
//Should never reach this point!
while(1);
return 0;
}
void irTxInit(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(IR_TX_CARRIER_RCC, ENABLE);
RCC_APB2PeriphClockCmd(IR_TX_CARRIER_TIMER_RCC, ENABLE);
// Configure the GPIO for the timer output
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Pin = IR_TX_CARRIER_PIN;
GPIO_Init(IR_TX_CARRIER_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource8, GPIO_AF_TIM10);
// Time base configuration
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
TIM_TimeBaseStructure.TIM_Period = 0xFFFF;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(IR_TX_CARRIER_TIMER, &TIM_TimeBaseStructure);
// PWM channel configuration
TIM_OCStructInit(&TIM_OCInitStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 0;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
// Configure Output Compare for PWM
IR_TX_CARRIER_TIMER_CH_Init(IR_TX_CARRIER_TIMER, &TIM_OCInitStructure);
IR_TX_CARRIER_TIMER_CH_PreloadConfig(IR_TX_CARRIER_TIMER, TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(IR_TX_CARRIER_TIMER, ENABLE);
TIM_Cmd(IR_TX_CARRIER_TIMER, ENABLE);
}
Code: Select all
17:24:21 **** Build of configuration Default for project crazyflie-firmware ****
make cload
python3 -m cfloader flash cf2.bin stm32-fw
Restart the Crazyflie you want to bootload in the next
10 seconds ...
done!
Connected to bootloader on Crazyflie 2.0 (version=0x10)
Target info: nrf51 (0xFE)
Flash pages: 232 | Page size: 1024 | Buffer pages: 1 | Start page: 88
144 KBytes of flash available for firmware image.
Target info: stm32 (0xFF)
Flash pages: 1024 | Page size: 1024 | Buffer pages: 10 | Start page: 16
1008 KBytes of flash available for firmware image.
Flashing 1 of 1 to stm32 (fw): 184595 bytes (181 pages) ..........10..........10..........10..........10..........10..........10..........10..........10..........10..........10..........10..........10..........10..........10..........10..........10..........10..........10.1
Reset in firmware mode ...
17:25:16 Build Finished (took 54s.83ms)
The only thing I'm doubted about is that there are some bug signs in some lines of code just like in the image attached. When I click in the bug, it says:
Code: Select all
Symbol .... could not be resolved, return 0
I will appreciate any help. Please tell me if you see any problem.