konsgn / BlueMagic

BluePill/BlackMagicProbe support for CSR Programming
19 stars 2 forks source link

how to compile this~~~ #1

Closed zeg closed 5 years ago

zeg commented 6 years ago

sorry for bothering

I am a newbie in this, only have some experience on STM32duino

how should I compile this program for bluepill?

konsgn commented 6 years ago

1st: make sure you have arm-none-eabi-gcc installed. This is the compiler that allows you to generate code for an arm architecture. on an ARCH Linux system install is sudo pacman -S arm-none-eabi-gcc

2nd, clone this repository in a folder and also execute the following commands:

git submodule init
git submodule update

Those two commands should get you the libopencm3 version that I compiled against.

3rd, run make in the directory

Alternatively, just use the pre-compiled bin file I included.

konsgn commented 6 years ago

Also note,

The blue pill in particular can only talk at 3.3V. While that should be fine for working with the bc417 (HC05 chipset), I would really not recommend doing that with a csr86x5.

In figuring out this code, I burnt up my hacked headphones original bluetooth module, and ended up designing a replacement based around the F-3188 module, Unless you have a circuit that has resistors between each of the data lines and the spi interface.

zeg commented 6 years ago

er...I use usb-ttl upload bluemagic.bin to the bluepill

then connect bluepill to computer through usb

windows say got a "unknown usb device(device descriptor request failed)"

I try to manual update driver with the "csr usb<>spi converter" in bluesuite but windows still give device descriptor failed

is there something wrong?

konsgn commented 6 years ago

merrp, this is compiled in a way that assumes that there is a bootloader located at address 0x08000000 and that the bootloader jumps to an application that is located at 0x08002000. As such the bin file gets loaded into the address 0x08002000.

Both the blackmagic probe and the maple bootloader work this way.

I would recommend loading the maple loader as mentioned here: LINK

What I did to load bluemagic was: 1) get the bootloader installed 2) program on test arduino code and verify the test ran 3) copy the program command from the terminal window and replace the bin file it directs to with the location of the bluemagic.bin

PS: If you are using that flash loader utility, it may be easier to load the bootloader with it, then also program in the bluemagic.bin file to the offset 0x08002000.

zeg commented 6 years ago

still have some poblem here

first use USB-TTL upload the stm32duino bootloader generic_boot20_pb12.bin

then connect usb , use arduino make a blink test

C:\................./tools/win/maple_upload.bat COM4 2 1EAF:0003 C:\............/Blink.ino.bin
maple_loader v0.1
Resetting to bootloader via DTR pulse
Reset via USB Serial Failed! Did you select the right serial port?
Assuming the board is in perpetual bootloader mode and continuing to attempt dfu programming...

Searching for DFU device [1EAF:0003]...
Found it!

Opening USB Device 0x1eaf:0x0003...
Found Runtime: [0x1eaf:0x0003] devnum=1, cfg=0, intf=0, alt=2, name="STM32duino bootloader v1.0  Upload to Flash 0x8002000"
Setting Configuration 1...
Claiming USB DFU Interface...
Setting Alternate Setting ...
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
Transfer Size = 0x0400
bytes_per_hash=315
Starting download: [##################################################] finished!
error resetting after download: usb_reset: could not reset device, win error: The system cannot find the file specified.

state(8) = dfuMANIFEST-WAIT-RESET, status(0) = No error condition is present

Done!

test ok, it start blink

then I upload bluemagic

C:\......./win/maple_upload.bat COM4 2 1EAF:0003 "D:\......\bluemagic.bin"
maple_loader v0.1
Resetting to bootloader via DTR pulse
Reset via USB Serial Failed! Did you select the right serial port?
Assuming the board is in perpetual bootloader mode and continuing to attempt dfu programming...

Searching for DFU device [1EAF:0003]...
Found it!

Opening USB Device 0x1eaf:0x0003...
Found Runtime: [0x1eaf:0x0003] devnum=1, cfg=0, intf=0, alt=2, name="STM32duino bootloader v1.0  Upload to Flash 0x8002000"
Setting Configuration 1...
Claiming USB DFU Interface...
Setting Alternate Setting ...
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
Transfer Size = 0x0400
bytes_per_hash=694
Starting download: [##################################################] finished!
state(8) = dfuMANIFEST-WAIT-RESET, status(0) = No error condition is present
error resetting after download: usb_reset: could not reset device, win error: The system cannot find the file specified.
Done!

Resetting USB to switch back to runtime mode

timeout waiting for COM4 serial

then windows device manager show a new "CSR USB<>SPI convertor"

run bluetest3.exe in bluesuite (no csr chip connect), can see a "USB SPI (31337)" port,

Opening USB SPI (31337).
Failed to open USB SPI (31337).
....

this mean it work correct or not?

then if I reset the bluepill or reconnect usb ,"CSR USB<>SPI convertor" will disappear won't show again

is there something wrong or I must connect some csr chip to test?

konsgn commented 6 years ago

What is it you're trying to do?

The bluetest program is for testing rf functionality, I haven't heard of anyone using it/ haven't tested it myself.

Check this link for popular commands that may be usefull. Word of warning though, Ignore everything regarding tweaking dll's or custom driver files. This code/ the original Tiva code should look like an official programmer to the software/ operating system. As such using an ftdi chip/ hacking the dll's is not necessary.

A quick overview :

In terms of whats available/used, blueflash will allow you to download/ load on the "VM" applications. PStools will give you a list of the common/ unique ps keys and allow you to change them. PSkeys cover everything from names to mac id, to tuning, so be careful playing with them, I recommend dumping the full list immediately and labeling your module with a unique sticker to associate the dump. Tuning settings are not things you want to mix up.

For more advanced chips like the CSR8645/8635, the dumper loses it's functionality as the VM's are encrypted/ protected. However the PStool is still relevant. Also for these chips there is a "CSR Headset Tool. Version 3.0.70" that can be useful. But be careful with that headset config tool, Make sure you constantly keep versions of your tweaks as you change them, and do so very slowly. You may find that the 3.0.70 version is outdated compared to your VM, and that means that ticking an innocent checkbox wreaks havoc on the functionality(in particular the audio codecs enabled & gatt battery reporting). When things go haywire, recover by merging a previous good pstool dump.

zeg commented 6 years ago

I am trying to change some setting of csr chip

now the poblem is after reset or reconnect bluemagic, the "CSR USB<>SPI convertor" device will disappear won't show again~~

konsgn commented 6 years ago

... have you tried turning it off and on again? (The computer I mean)

Sorry I can't be more helpfull, that is really weird. Maybe that bluetest did something strange with the device.

I will try to take a look at that tool sometime later today. In the meantime, re-do the install process, and try using blueflash and pstool.

Sidenote, you may have needed to install bluesuite drivers for their csr-spi device. On windows 10 that sometimes means going into bios and disabling driver verification temporarily. I don't remember if you have to do that bios method for this. Have you installed the official bluesuite drivers?

zeg commented 6 years ago

after reset or reconnect usb, device manager keep show a "Maple DFU" device, looks like stuck at init?

I will make more test

zeg commented 6 years ago

looks like this libopencm3 not work with stm32duino bootloader? (https://github.com/rogerclarkmelbourne/STM32duino-bootloader/blob/master/binaries/generic_boot20_pb12.bin)

I try compile and upload some basic test with arduino_opencm3, seems just not run

konsgn commented 6 years ago

Tried sending this as email earler. I guess it didn't show:

Ya, seems like the bootloader erased The application. But hey, you can now upload subsequent programs like the bluemagic.bin using the maple loader directly through the usb. Load on the bluemagic.bin file.

Btw, you are right, each of the applications will try to get a connection started with the target chip. Without a chip attached, you can see the spi interface and the serial number of the converter, but cant do anything else. Bluetest3 in particular goes into a loop constantly probing for a target chip.

Ps: the bootloader is unrelated to libopencm3

konsgn commented 6 years ago

Any Success?

zeg commented 6 years ago

I make a linux virtual machine and build all things up

find that

1 stm32duino bootloader only work with arduino ide made program

2 use stmflashloader upload opencm based blink test and success run

3 upload pre-compiled bluemagic still give "device descriptor request failed" error

now I can compile opencm program myself , I will make some debug later

zeg commented 6 years ago

aha~I made stm32duino bootloader work with libopencm3 application , this will make test easier

konsgn commented 6 years ago

One thing I would recommend is try using a windows7 VM to do the software programming of the target. The software tools available are quite old, and while I have gotten it to work on Win10, I believe there will be less issues with win7.

zeg commented 6 years ago

ok I found the poblem

pDEBUG =0 will cause "one shot work", can't find usb device after reconnect

set pDEBUG to 1 and recompile make it work

now I wired spi with 1k resistor and successful reconfig a csr64215 module

konsgn commented 6 years ago

I must say, I couldn't reproduce your issue. I'm happy to hear you got it working though! Do be careful of voltage translations though.

One cool thing about the print debugging is that if you listen to PA9 you should be able to see exactly what is happening/ what the software is trying to do with each read and write. I believe the baud is set to 115200.