Community-BL-IOT / pio-bl602-boufallo-arduino-test

A test for using PlatformIO with the new extension for building https://github.com/pine64/ArduinoCore-bouffalo
16 stars 0 forks source link

can't upload #2

Closed tonyxforce closed 1 year ago

tonyxforce commented 1 year ago

i tried to upload using the readme 1) i pulled BOOT pin to 3.3v 2) turned on chip 3) removed the bridge between 3.3v and BOOT 4) pressed upload on pio

ouput:

 *  Executing task: C:\Users\domi\.platformio\penv\Scripts\platformio.exe run --target upload --environment pinecone_bl602 --upload-port COM6 

Processing pinecone_bl602 (platform: https://github.com/Community-BL-IOT/platform-sifive.git; board: pinecone; framework: arduino)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/sifive/pinecone.html
PLATFORM: SiFive (5.0.0+sha.003edcf) > PineCone (BL602)
HARDWARE: SIFIVE_E24 192MHz, 320KB RAM, 1.25MB Flash
DEBUG: Current (qemu) On-board (qemu) External (ftdi, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
 - framework-arduinobouffalo @ 5.1.210913+sha.f6ec713
 - framework-bl-iot-sdk-arduino @ 5.1.210913+sha.012b766
 - tool-bl60x-flash @ 1.1000.0+sha.3172237
 - tool-jlink @ 1.77001.0 (7.70.1)
 - tool-openocd-riscv @ 2.1000.20190927 (10.0)
 - toolchain-riscv @ 1.80300.190927 (8.3.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 2 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Checking size .pio\build\pinecone_bl602\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [===       ]  27.2% (used 89224 bytes from 327680 bytes)
Flash: [          ]   3.2% (used 42374 bytes from 1310720 bytes)
Configuring upload protocol...
AVAILABLE: bl60x-flash, ftdi, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa
CURRENT: upload_protocol = bl60x-flash
Looking for upload port...
Using manually specified: COM6
Uploading .pio\build\pinecone_bl602\firmware.bin
Loading helper binary
21872 bytes @ 0x22010000

  0%|          | 0.00/21.9k [00:00<?, ?byte/s]
 37%|███▋      | 8.16k/21.9k [00:00<00:00, 45.5kbyte/s]
 75%|███████▍  | 16.3k/21.9k [00:00<00:00, 45.5kbyte/s]
100%|██████████| 21.9k/21.9k [00:00<00:00, 45.3kbyte/s]
100%|██████████| 21.9k/21.9k [00:00<00:00, 45.4kbyte/s]

Traceback (most recent call last):
  File "C:\Users\domi\.platformio\packages\tool-bl60x-flash\bl602-flasher.py", line 233, in <module>
    main()
  File "C:\Users\domi\.platformio\packages\tool-bl60x-flash\bl602-flasher.py", line 229, in main
    efl_program_img(ser, 0x10000, data)
  File "C:\Users\domi\.platformio\packages\tool-bl60x-flash\bl602-flasher.py", line 169, in efl_program_img
    efl_cmd_flash_erase(ser, addr, data_len)
  File "C:\Users\domi\.platformio\packages\tool-bl60x-flash\bl602-flasher.py", line 139, in efl_cmd_flash_erase
    expect_ok(ser)
  File "C:\Users\domi\.platformio\packages\tool-bl60x-flash\bl602-flasher.py", line 53, in expect_ok
    if data[0] != 0x4f or data[1] != 0x4b:
IndexError: index out of range
*** [upload] Error 1
======================================================================== [FAILED] Took 15.67 seconds ========================================================================
maxgerhardt commented 1 year ago

Which exact dev board are you working on? Have you tried lowering the upload speed to e.g.

upload_speed = 115200

in the platformio.ini? The default is 2 million (baud).

maxgerhardt commented 1 year ago

My bad, this will not work, the baud rate is handled internally in the script. It's 500k at the sync and 2M at the second stage.

https://github.com/Community-BL-IOT/pio-bl60x-flash/blob/main/bl602-flasher.py#L212-L224

Have you tried using a different USB-UART converter that can handle these high speeds? Like an FTDI FT232R instead of a CH340.

tonyxforce commented 1 year ago

This is my platformio.ini file:

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:pinecone_bl602]
platform = https://github.com/Community-BL-IOT/platform-sifive.git
board = pinecone
framework = arduino
monitor_speed = 115200

i have tried both 115200 and 2000000 but i dont have another UART converter only one that has a CH340G maybe can i use an arduino leonardo?

tonyxforce commented 1 year ago

can it be a problem that i dont have either RTS or CTS pin of the UART converter connected anywhere?

maxgerhardt commented 1 year ago

Per docs the UART bootloader does not support RTS/CTS, it's just RXD and TXD. The script seems to use these pins regardless as maybe a reset, but that then depends on the board hardware. Often times it's used to reset chip via a capacitive connection from RTS or CTS do the RESET pin of the chip. If you haven't done so, you can try pressing reset right before the upload starts because the bootloader does have 2 second timeout.

A Leonardo uses 5V logic level, so to convert it to e generic USB-UART adapter you'll have to use a resistor divider from its TX to the BL602's RX. (In the reverse path from BL602's TX to Leonardo's RX no such thing is needed). Further the sketch has to be able to cope with dynamically changing baud rates. This could be solution to that.

Are you using a Pine64 Pinecone board or a different one?

maxgerhardt commented 1 year ago

You can also try different flashing software, e.g. the Boufallo Lab Dev Cube software from https://dev.bouffalolab.com/download.

tonyxforce commented 1 year ago

Are you using a Pine64 Pinecone board or a different one?

im using a $2 magic home rgb led driver board

maxgerhardt commented 1 year ago

Just open the program, select BL602/4, go to the "IOT" tab, select your UART port on the right, set address as 0x10000, select the .bin file that PlatformIO produces are you hit "Build" (.pio/build/pinecone_bl602/firmware.bin), make sure your board is in bootloader mode (on my board hold down the D8 button, press reset, release reset, release D8) and press Create + Download.

Works nicely.

grafik

tonyxforce commented 1 year ago

I can't seem to find firmware.bin, can i use firmware.hex?

tonyxforce commented 1 year ago

I tried that and got this errror: image

maxgerhardt commented 1 year ago

There currently is a bug where the bin is only created when you use the "Upload" project task. So execute that once and you should have the firmware.bin file, even if PlatformIO upload fails.

If you're getting a handshake error then the chip may not be in bootloader mode or you need to reset it again. You may also try to reduce the baud rate.

tonyxforce commented 1 year ago

i figured it out, my 3.3v line had contact issues (i was using a jumper cable), now it errors out while trying to read mac address

tonyxforce commented 1 year ago

(error code 0023)

maxgerhardt commented 1 year ago

Does it upload via PlatformIO's "Upload" task now normally maybe?

Have you tried power-cycling + resetting it?

tonyxforce commented 1 year ago

Does it upload via PlatformIO's "Upload" task now normally maybe?

still the same error

Have you tried power-cycling + resetting it?

The board doesn't have a "reset" button so when i need to reset it i unplug the power connector, and i plug it back in (while connecting BOOT(flash) pin and 3.3v) I have gone in and out of programming/flashing mode quite a few times, so i did reset it a few times

tonyxforce commented 1 year ago

Also, this is my setup if that is any help: image image image image

UART converter - bl602

RXD - TX TXD - RX GND - GND CTS - not connected (nc) RTS - nc 3.3v - nc

also bl602 BOOT and 3.3v is connected to some loose wires that i connect togedher on powerup

tonyxforce commented 1 year ago

I just found this: https://github.com/Community-BL-IOT/ArduinoCore-bouffalo

Should i try to use this with the arduino 1 ide?

tonyxforce commented 1 year ago

tried it, same error as in platformio

maxgerhardt commented 1 year ago

Unsurprising since it uses the same upload tool as we do in PlatformIO.

I'd recommend to just get a new USB-UART of type CP2102 or FT232R to rule out problems due to the CH340. The DT-10 dev-board I use has a CP2102 on-board.

maxgerhardt commented 1 year ago

Test it out. If you hold the ESP8266 in reset (CHIP_PD) so that it lets go of TX/RX it may work. Otherwise such an adapter can be bough for like 7€..

tonyxforce commented 1 year ago

i tried it and IT WORKED! that was the problem, now both the buffalo dev cube and platformIO can upload code to it now i have to figure out how to write usable code for it

maxgerhardt commented 1 year ago

Great! The Arduino core is at a very rudimentary state right now with only GPIO, Serial, I2C and SPI implemented. So not even WiFi. But we do support writing applications against the native Boufallo SDK that has those capabilities, see example. Or you take it as an oportunity to help improve the Arduino core.