Skip to content

Commit

Permalink
Upload works now for Krooz. Testing flight settigs...
Browse files Browse the repository at this point in the history
  • Loading branch information
softsr committed Jan 17, 2013
1 parent 80188ad commit 8ccae56
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 2 deletions.
5 changes: 5 additions & 0 deletions conf/Makefile.stm32
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,12 @@ ifeq ($(FLASH_MODE),DFU)
# DFU flash mode
upload: $(OBJDIR)/$(TARGET).bin
@echo "Using stm32 mem dfu loader"
ifeq ($(ARCH_L), )
$(PYTHON) $(PAPARAZZI_SRC)/sw/tools/dfu/stm32_mem.py $^
else ifeq ($(ARCH_L),f4)
$(PYTHON) $(PAPARAZZI_SRC)/sw/tools/dfu/stm32_f4_mem.py $^
endif

#
# serial flash mode
else ifeq ($(FLASH_MODE),SERIAL)
Expand Down
57 changes: 57 additions & 0 deletions conf/radios/mx-16.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0"?>
<!-- $Id: cockpitSX.xml 3610 2009-07-02 16:35:18Z poine $
--
-- (c) 2006 Pascal Brisset, Antoine Drouin
--
-- This file is part of paparazzi.
--
-- paparazzi is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2, or (at your option)
-- any later version.
--
-- paparazzi is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with paparazzi; see the file COPYING. If not, write to
-- the Free Software Foundation, 59 Temple Place - Suite 330,
-- Boston, MA 02111-1307, USA.
-->

<!--
-- Attributes of root (Radio) tag :
-- name: name of RC
-- data_min: min width of a pulse to be considered as a data pulse
-- data_max: max width of a pulse to be considered as a data pulse
-- sync_min: min width of a pulse to be considered as a synchro pulse
-- sync_max: max width of a pulse to be considered as a synchro pulse
-- pulse_type: POSITIVE ( Futaba and others) | NEGATIVE (JR)
-- min, max and sync are expressed in micro-seconds
-->

<!--
-- order in section = order in the PPM frame
-- Attributes of channel tag :
-- ctl: name of the command on the transmitter - only for displaying
-- function: logical command
-- averaged: channel filtered through several frames (for discrete commands)
-- min: minimum pulse length (micro-seconds)
-- max: maximum pulse length (micro-seconds)
-- neutral: neutral pulse length (micro-seconds)
-- Note: a command may be reversed by exchanging min and max values
-->

<!DOCTYPE radio SYSTEM "radio.dtd">
<radio name="mx-16" data_min="967" data_max="2033" sync_min ="5000" sync_max ="15000" pulse_type="NEGATIVE">
<channel ctl="MOTOR" function="THROTTLE" min="1100" neutral="1100" max="1900" average="0"/>
<channel ctl="QUERRUDER" function="ROLL" min="1900" neutral="1500" max="1100" average="0"/>
<channel ctl="HOEHENRUDER" function="PITCH" min="1900" neutral="1500" max="1100" average="0"/>
<channel ctl="SEITENRUDER" function="YAW" min="1900" neutral="1500" max="1100" average="0"/>
<channel ctl="ROCKER" function="MODE" min="1100" neutral="1500" max="1900" average="1"/>
<channel ctl="SHOTS" function="SHOTS" min="1100" neutral="1100" max="1900" average="1"/>
<channel ctl="PHOTO_VIDEO" function="PH_VD" min="1100" neutral="1500" max="1900" average="1"/>
<channel ctl="CAMERA" function="CAM" min="1100" neutral="1500" max="1900" average="1"/>
</radio>
4 changes: 2 additions & 2 deletions sw/airborne/arch/stm32/mcu_periph/adc_arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ static inline void adc_init_rcc( void )
timer_set_period(timer, 0xFF);
timer_set_prescaler(timer, 0x8);
#elif defined(STM32F4)
timer_set_period(timer, 0xFFFF);
timer_set_prescaler(timer, 0x53);
timer_set_period(timer, 0xFFFF);
timer_set_prescaler(timer, 0x53);
#endif
//timer_set_clock_division(timer, 0x0);
/* Generate TRGO on every update. */
Expand Down
123 changes: 123 additions & 0 deletions sw/tools/dfu/stm32_f4_mem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#!/usr/bin/python
#
# stm32_mem.py: STM32 memory access using USB DFU class
# Copyright (C) 2011 Black Sphere Technologies
# Written by Gareth McMullin <gareth@blacksphere.co.nz>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from time import sleep
import struct
from sys import stdout, argv

import usb
import dfu

APP_ADDRESS = 0x08004000
SECTOR_SIZE = 2048

CMD_GETCOMMANDS = 0x00
CMD_SETADDRESSPOINTER = 0x21
CMD_ERASE = 0x41

def stm32_erase(dev, addr):
erase_cmd = struct.pack("<BL", CMD_ERASE, addr)
dev.download(0, erase_cmd)
while True:
status = dev.get_status()
if status.bState == dfu.STATE_DFU_DOWNLOAD_BUSY:
sleep(status.bwPollTimeout / 1000.0)
if status.bState == dfu.STATE_DFU_DOWNLOAD_IDLE:
break

def stm32_write(dev, data):
dev.download(2, data)
while True:
status = dev.get_status()
if status.bState == dfu.STATE_DFU_DOWNLOAD_BUSY:
sleep(status.bwPollTimeout / 1000.0)
if status.bState == dfu.STATE_DFU_DOWNLOAD_IDLE:
break

def stm32_manifest(dev):
dev.download(0, "")
while True:
try:
status = dev.get_status()
except:
return
sleep(status.bwPollTimeout / 1000.0)
if status.bState == dfu.STATE_DFU_MANIFEST:
break

if __name__ == "__main__":
print
print "USB Device Firmware Upgrade - Host Utility -- version 1.2"
print "Copyright (C) 2011 Black Sphere Technologies"
print "Copyright (C) 2012 Transition Robotics Inc."
print "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>"
print

devs = dfu.finddevs()
if not devs:
print "No devices found!"
exit(-1)

for dev in devs:
dfudev = dfu.dfu_device(*dev)
try:
man = dfudev.handle.getString(dfudev.dev.iManufacturer, 30)
product = dfudev.handle.getString(dfudev.dev.iProduct, 30)
serial = dfudev.handle.getString(dfudev.dev.iSerialNumber, 40)
except:
print "Could not access the description strings of a DFU device. Maybe the OS driver is claiming it?"
continue
if man == "Black Sphere Technologies": break
if man == "Transition Robotics Inc.": break
if man == "STMicroelectronics": break

print "Device %s: ID %04x:%04x %s - %s - %s" % (dfudev.dev.filename,
dfudev.dev.idVendor, dfudev.dev.idProduct, man, product, serial)

try:
state = dfudev.get_state()
except:
print "Failed to read device state! Assuming APP_IDLE"
state = dfu.STATE_APP_IDLE
if state == dfu.STATE_APP_IDLE:
dfudev.detach()
print "Run again to upgrade firmware."
exit(0)

dfudev.make_idle()

try:
bin = open(argv[1], "rb").read()
except:
print "Could not open binary file."
raise

addr = APP_ADDRESS
while bin:
print ("Programming memory at 0x%08X\r" % addr),
stdout.flush()
stm32_erase(dfudev, addr)
stm32_write(dfudev, bin[:SECTOR_SIZE])

bin = bin[SECTOR_SIZE:]
addr += SECTOR_SIZE

stm32_manifest(dfudev)

print "\nAll operations complete!\n"

0 comments on commit 8ccae56

Please sign in to comment.