From: Xavier L. <Ba...@us...> - 2011-03-16 15:13:20
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot". The branch, master has been updated via d67edc588cdf218373b4dfeab3453c77e2242a36 (commit) via 85de23d27522edc5162dfbd3c75713163963cfec (commit) via 2cd2334d1be8b5d90e38c45c6f6250f9e41e9050 (commit) via eb637d931a5f01f8ca74d54fd44a5a116f4505b2 (commit) via 8f295e48a1048325ac191b996632bf73301a0363 (commit) from 22cfcc212fc0274b07ea35f20f3fe87943b245d9 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit d67edc588cdf218373b4dfeab3453c77e2242a36 Author: Xavier Lagorce <Xav...@cr...> Date: Wed Mar 16 16:01:52 2011 +0100 [Controller_Motor_STM32] Little changes in test firmware main function * Blink LEDs at the end of initialization sequence to show we are alive * More friendly speed test sequence for repeated testing commit 85de23d27522edc5162dfbd3c75713163963cfec Author: Xavier Lagorce <Xav...@cr...> Date: Wed Mar 16 16:00:11 2011 +0100 [Controller_Motor_STM32] Refactored can_monitor to use Events instead of callbacks commit 2cd2334d1be8b5d90e38c45c6f6250f9e41e9050 Author: Xavier Lagorce <Xav...@cr...> Date: Wed Mar 16 15:40:11 2011 +0100 [Controller_Motor_STM32] Add Signal support to used kernel features commit eb637d931a5f01f8ca74d54fd44a5a116f4505b2 Author: Xavier Lagorce <Xav...@cr...> Date: Wed Mar 16 15:39:35 2011 +0100 [Controller_Motor_STM32] Added LEDs indicator on motor command saturation commit 8f295e48a1048325ac191b996632bf73301a0363 Author: Xavier Lagorce <Xav...@cr...> Date: Sat Mar 12 16:31:12 2011 +0100 [Controller_Motor_STM32] Added a simple CAN monitor for motor identification ----------------------------------------------------------------------- Changes: diff --git a/elec/boards/Controller_Motor_STM32/Firmware/bertos/cpu/cortex-m3/drv/can_stm32.c b/elec/boards/Controller_Motor_STM32/Firmware/bertos/cpu/cortex-m3/drv/can_stm32.c index b92fb9f..f47e99a 100644 --- a/elec/boards/Controller_Motor_STM32/Firmware/bertos/cpu/cortex-m3/drv/can_stm32.c +++ b/elec/boards/Controller_Motor_STM32/Firmware/bertos/cpu/cortex-m3/drv/can_stm32.c @@ -137,14 +137,13 @@ void can_hw_init(void) can_drv_init(CAND1); CAND1->can = CAN1; - // Set the pins to the right mode for CAN. - stm32_gpioRemap(GPIO_REMAP1_CAN1, GPIO_REMAP_ENABLE); - stm32_gpioPinConfig((struct stm32_gpio *)GPIOB_BASE, BV(8), GPIO_MODE_IPU, GPIO_SPEED_50MHZ); - stm32_gpioPinConfig((struct stm32_gpio *)GPIOB_BASE, BV(9), GPIO_MODE_AF_PP, GPIO_SPEED_50MHZ); - // Enable the clocks RCC->APB2ENR |= RCC_APB2_AFIO; - RCC->APB2ENR |= RCC_APB2_GPIOB; + RCC->APB2ENR |= RCC_APB2_GPIOA; + + // Set the pins to the right mode for CAN. + stm32_gpioPinConfig((struct stm32_gpio *)GPIOA_BASE, BV(11), GPIO_MODE_IN_FLOATING, GPIO_SPEED_50MHZ); + stm32_gpioPinConfig((struct stm32_gpio *)GPIOA_BASE, BV(12), GPIO_MODE_AF_PP, GPIO_SPEED_50MHZ); } void can_hw_start(can_driver *drv) { diff --git a/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/can_monitor.c b/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/can_monitor.c new file mode 100644 index 0000000..ccbd670 --- /dev/null +++ b/elec/boards/Controller_Motor_STM32/Firmware/controller_motor_stm32/can_monitor.c @@ -0,0 +1,98 @@ +/* + * can_monitor.c + * ------------- + * Copyright : (c) 2011, Xavier Lagorce <Xav...@cr...> + * Licence : BSD3 + * + * This file is a part of [kro]bot. + */ + +#include "can_monitor.h" +#include "hw/hw_led.h" + +typedef struct { + uint16_t encoder1_pos __attribute__((__packed__)); + uint16_t encoder2_pos __attribute__((__packed__)); + uint8_t encoder1_dir; + uint8_t encoder2_dir; + uint16_t padding __attribute__((__packed__)); +} encoder_msg_t; + +typedef union { + encoder_msg_t data_f; + uint32_t data32[2]; +} encoder_can_msg_t; + +// Process for communication +static void NORETURN canMonitor_process(void); + +void canMonitorInit(void) { + can_config cfg; + + // Configure CAN driver + cfg.mcr = CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP; + cfg.btr = CAN_BTR_SJW(0) | CAN_BTR_TS1(8) | CAN_BTR_TS2(1) | CAN_BTR_BRP(6);// | CAN_BTR_LBKM; // Add LBKM for loopback mode + cfg.n_filters = 0; + cfg.filters = NULL; + + // Initialize CAN driver + can_init(); + can_start(CAND1, &cfg); + + // Start communication process + proc_new(canMonitor_process, NULL, KERN_MINSTACKSIZE * 8, NULL); +} + +static void NORETURN canMonitor_process(void) { + encoder_can_msg_t msg; + can_tx_frame txm; + Timer timer_can; + uint8_t ind = 0; + + // Initialize constant parameters of TX frame + txm.dlc = 6; + txm.rtr = 0; + txm.ide = 1; + txm.sid = 0; + + timer_setDelay(&timer_can, ms_to_ticks(1000)); + timer_setEvent(&timer_can); + while(1) { + + timer_add(&timer_can); + + // Sending ENCODER1 and ENCODER2 data + msg.data_f.encoder1_pos = getEncoderPosition(ENCODER1); + msg.data_f.encoder2_pos = getEncoderPosition(ENCODER2); + msg.data_f.encoder1_dir = getEncoderDirection(ENCODER1); + msg.data_f.encoder2_dir = getEncoderDirection(ENCODER2); + + txm.data32[0] = msg.data32[0]; + txm.data32[1] = msg.data32[1]; + txm.eid = 100; + can_transmit(CAND1, &txm, ms_to_ticks(10)); + + // Sending ENCODER3 and ENCODER4 data + msg.data_f.encoder1_pos = getEncoderPosition(ENCODER3); + msg.data_f.encoder2_pos = getEncoderPosition(ENCODER4); + msg.data_f.encoder1_dir = getEncoderDirection(ENCODER3); + msg.data_f.encoder2_dir = getEncoderDirection(ENCODER4); + + txm.data32[0] = msg.data32[0]; + txm.data32[1] = msg.data32[1]; + txm.eid = 101; + can_transmit(CAND1, &txm, ms_to_ticks(10)); + + // Wait for the next transmission timer + timer_waitEvent(&timer_can); + // blink ! + if (ind == 0) { + LED2_OFF(); + ind = 1 |