ubuntu 16.04(x64)编译LimeSDR v1.4的USB固件

最近在捣鼓LimeSDR,如果只使用USB供电的话,默认USB固件只向系统声明了400MA的电流。

明显当设备全功率运行的话,是不够设备使用的,全功率大约是3W以上的样子,因此,我们需要调整USB固件,向系统多申请些电流。

USB 3.0可以提供900MA的电流。

下面是如何编译LimeSDRUSB固件:

$ cd ~

$ wget http://www.mobibrw.com/wp-content/uploads/2018/02/FX3_SDK_Linux_v1.3.3.tar.gz

$ tar -zxvf FX3_SDK_Linux_v1.3.3.tar.gz

$ tar -zxvf ARM_GCC.tar.gz

$ tar -zxvf fx3_firmware_linux.tar.gz

$ tar -zxvf eclipse_x64.tar.gz

$ export PATH=~/arm-2013.11/bin:$PATH

$ export FX3_INSTALL_PATH=~/cyfx3sdk

$ export ARMGCC_INSTALL_PATH=~/arm-2013.11

$ export ARMGCC_VERSION=4.8.1

#编译镜像打包工具
$ cd ~/cyfx3sdk/util/elf2img

$ gcc elf2img.c -o elf2img -Wall

$ cd ~

$ git clone https://github.com/myriadrf/LimeSDR-USB_FX3.git

$ ./eclipse/ezUsbSuite

参照下面的步骤导入工程(但是要注意的是,用ezUsbSuite开发,目前在不修改工程的情况下,只能在Windows下开发,原因是模板设置的时候,部分路径没有配置正确)

对于ubuntu系统,并且需要使用命令行编译的情况,需要手工生成如下几个文件( 这几个文件根据Debug目录下的配置文件修改来的

$ cd LimeSDR-USB_FX3

$ mkdir Release

$ cd Release

$ touch makefile

$ touch objects.mk

$ touch sources.mk

$ touch subdir.mk

编译配置文件的内容如下:

makefile

################################################################################
# Automatically-generated file. Do not edit!
################################################################################

RM := rm -rf

# All of the sources participating in the build are defined here
-include sources.mk
-include subdir.mk
-include objects.mk

ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(ASM_DEPS)),)
-include $(ASM_DEPS)
endif
ifneq ($(strip $(S_UPPER_DEPS)),)
-include $(S_UPPER_DEPS)
endif
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
endif

-include ../makefile.defs

# Add inputs and outputs from these tool invocations to the build variables 
SECONDARY_LIST += \
LimeSDR-USB_FX3.lst \

SECONDARY_SIZE += \
LimeSDR-USB_FX3.siz \


# All Target
all: LimeSDR-USB_FX3.elf secondary-outputs

# Tool invocations
LimeSDR-USB_FX3.elf: $(OBJS) $(USER_OBJS)
	@echo 'Building target: $@'
	@echo 'Invoking: ARM Sourcery Windows GCC C Linker'
	arm-none-eabi-gcc $(OBJS) $(USER_OBJS) $(LIBS) -T"$(FX3_INSTALL_PATH)/firmware/common/fx3.ld" -nostartfiles -Wl,-Map,LimeSDR-USB_FX3.map -Wl,-d -Wl,--no-wchar-size-warning -Wl,--entry,CyU3PFirmwareEntry "$(FX3_INSTALL_PATH)/firmware/u3p_firmware/lib/fx3_release/cyfxapi.a" "$(FX3_INSTALL_PATH)/firmware/u3p_firmware/lib/fx3_release/cyu3lpp.a" "$(FX3_INSTALL_PATH)/firmware/u3p_firmware/lib/fx3_release/cyu3threadx.a"  "$(ARMGCC_INSTALL_PATH)/arm-none-eabi/lib/libc.a" "$(ARMGCC_INSTALL_PATH)/lib/gcc/arm-none-eabi/4.8.1/libgcc.a" -mcpu=arm926ej-s -mthumb-interwork -o"LimeSDR-USB_FX3.elf"
	@echo 'Finished building target: $@'
	@echo ' '
	$(MAKE) --no-print-directory post-build

LimeSDR-USB_FX3.lst: LimeSDR-USB_FX3.elf
	@echo 'Invoking: ARM Sourcery Windows GNU Create Listing'
	arm-none-eabi-objdump -h -S LimeSDR-USB_FX3.elf > "LimeSDR-USB_FX3.lst"
	@echo 'Finished building: $@'
	@echo ' '

LimeSDR-USB_FX3.siz: LimeSDR-USB_FX3.elf
	@echo 'Invoking: ARM Sourcery Windows GNU Print Size'
	arm-none-eabi-size  --format=berkeley LimeSDR-USB_FX3.elf
	@echo 'Finished building: $@'
	@echo ' '

# Other Targets
clean:
	-$(RM) $(EXECUTABLES)$(OBJS)$(SECONDARY_LIST)$(SECONDARY_SIZE)$(ASM_DEPS)$(S_UPPER_DEPS)$(C_DEPS) LimeSDR-USB_FX3.elf
	-@echo ' '

post-build:
	-@echo 'Converting ELF to image (.img) format'
	-"$(FX3_INSTALL_PATH)/util/elf2img/elf2img" -i LimeSDR-USB_FX3.elf -o LimeSDR-USB_FX3.img
	-@echo ' '

secondary-outputs: $(SECONDARY_LIST) $(SECONDARY_SIZE)

.PHONY: all clean dependents
.SECONDARY: post-build

-include ../makefile.targets

objects.mk

################################################################################
# Automatically-generated file. Do not edit!
################################################################################

USER_OBJS :=

LIBS :=

sources.mk

################################################################################
# Automatically-generated file. Do not edit!
################################################################################

ELF_SRCS := 
OBJ_SRCS := 
ASM_SRCS := 
C_SRCS := 
S_UPPER_SRCS := 
O_SRCS := 
EXECUTABLES := 
OBJS := 
SECONDARY_LIST := 
SECONDARY_SIZE := 
ASM_DEPS := 
S_UPPER_DEPS := 
C_DEPS := 

# Every subdirectory with source files must be described here
SUBDIRS := \
. \

subdir.mk

################################################################################
# Automatically-generated file. Do not edit!
################################################################################

# Add inputs and outputs from these tool invocations to the build variables 
C_SRCS += \
../main.c \
../rtos_threadx.c \
../spi_flash_lib.c \
../usb_descriptors.c 

S_UPPER_SRCS += \
../cyfx_gcc_startup.S 

OBJS += \
./cyfx_gcc_startup.o \
./main.o \
./rtos_threadx.o \
./spi_flash_lib.o \
./usb_descriptors.o 

S_UPPER_DEPS += \
./cyfx_gcc_startup.d 

C_DEPS += \
./main.d \
./rtos_threadx.d \
./spi_flash_lib.d \
./usb_descriptors.d 


# Each subdirectory must supply rules for building sources it contributes
%.o: ../%.S
	@echo 'Building file: $<'
	@echo 'Invoking: ARM Sourcery Windows GCC Assembler'
	arm-none-eabi-gcc -x assembler-with-cpp -I"$(FX3_INSTALL_PATH)/firmware/u3p_firmware/inc" -Wall -Wa,-adhlns="$@.lst" -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -mcpu=arm926ej-s -mthumb-interwork -o "$@" "$<"
	@echo 'Finished building: $<'
	@echo ' '

%.o: ../%.c
	@echo 'Building file: $<'
	@echo 'Invoking: ARM Sourcery Windows GCC C Compiler'
	arm-none-eabi-gcc -D__CYU3P_TX__=1 -I"$(FX3_INSTALL_PATH)/firmware/u3p_firmware/inc" -I"..\." -Os -Wall -Wa,-adhlns="$@.lst" -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -mcpu=arm926ej-s -mthumb-interwork -o "$@" "$<"
	@echo 'Finished building: $<'
	@echo ' '

上面的文件生成后,在同一个Shell中执行

#编译之前确保 FX3_INSTALL_PATH,ARMGCC_INSTALL_PATH等几个环境变量已经正确定义

$ make clean

$ make

即可在Release目录下生成LimeSDR-USB_FX3.img,这个就是需要的刷机镜像。

参照ubuntu 16.04修复固件刷新失败的LimeSDR-USB V1.4,或者

$ LimeUtil --fw="LimeSDR-USB_FX3.img"

刷新固件即可。

至于电源控制部分的代码,调整usb_descriptors.c里面的Max power部分的数字即可:

/* Standard super speed configuration descriptor */
const uint8_t CyFxUSBSSConfigDscr[] __attribute__ ((aligned (32))) =
{
    /* Configuration descriptor */
    0x09,                           /* Descriptor size */
    CY_U3P_USB_CONFIG_DESCR,        /* Configuration descriptor type */
    0x46,0x00, 					    /* Length of this descriptor and all sub descriptors */
    0x01,                           /* Number of interfaces */
    0x01,                           /* Configuration number */
    0x00,                           /* COnfiguration string index */
    0x80,                           /* Config characteristics - Bus powered */
    0x32,                           /* Max power consumption of device (in 8mA unit) : 400mA */

刷新完成后,使用

#注意,ubuntu 16.04版本的lsusb -v ,命令显示的 MaxPower 参数是不正确的

$ usb-devices

查看设备供电情况。

如果固件代码无法成功下载,可以本站下载一份拷贝

参考链接


发布者

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注