I'm playing with STM32VL Discovery board. I want to get PWM signal on both - normal and complementary output.
I found out that TIM1 is PWM timer with complementary outputs and that TIM1_CH1 is connected as alternate function to PA8 and TIM1_CH1N is also connected as alternate to PB13.
I'm newbie so I'm scarred as hell about destroying my board so correct if I'm wrong but I think my code should look like:
part of board.h:
Code: Select all
/*
* Port A setup.
* Everything input with pull-up except:
* PA0 - Normal input (BUTTON).
* PA8 - Alternate Push Pull output 50MHz (TIM1_CH1)
*/
#define VAL_GPIOACRL 0x88888884 /* PA7...PA0 */
#define VAL_GPIOACRH 0x8888888B /* PA15...PA8 */
#define VAL_GPIOAODR 0xFFFFFFFF
/*
* Port B setup.
* Everything input with pull-up except:
* PB13 - Alternate Push Pull output 50MHz (TIM1_CH1N)
*/
#define VAL_GPIOBCRL 0x88888888 /* PB7...PB0 */
#define VAL_GPIOBCRH 0x88B88888 /* PB15...PB8 */
#define VAL_GPIOBODR 0xFFFFFFFFmy main.c:
Code: Select all
/*
ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "ch.h"
#include "hal.h"
static PWMConfig pwmcfg = {
10000, /* 10Khz PWM clock frequency */
10000, /* PWM period 1 second */
NULL, /* No callback */
/* Only channel 4 enabled */
{
{PWM_OUTPUT_DISABLED, NULL},
{PWM_OUTPUT_DISABLED, NULL},
{PWM_OUTPUT_DISABLED, NULL},
{PWM_OUTPUT_ACTIVE_HIGH, NULL},
},
0
};
int main(void)
{
halInit();
chSysInit();
/* Enables PWM output (of TIM1, channel 1) on LED connected to PA8 */
palSetPadMode(GPIOA, 8, PAL_MODE_ALTERNATE(2));
/* Enables PWM output (of TIM1, channel 1N) on LED connected to PB13 */
palSetPadMode(GPIOB, 13, PAL_MODE_ALTERNATE(2));
pwmStart(&PWMD1, &pwmcfg);
pwmEnableChannel(&PWMD1, 0, 5000);
while (TRUE) {
chThdSleepMilliseconds(5000);
}
}
I would be really appreciated if you could help me with that topic.
Thanks!!
Matthew
Update:
And don't know what's wrong but I get those errors from compiler ;/
Can you also help me with that?









