ESP32 serial port communication and firmware compilation problems

Issue #298 resolved
C WEIB created an issue

Hi,John

We are currently designing a development board for Microblocks, but have encountered some problems:
1, using the WCH CH9102X chip, this serial chip it supports drive-free (it can replace the CP2102), but in the Microblocks platform can not be burned in, stuck in Connecting ... This screen, I guess is in the https://bitbucket.org/john_maloney/smallvm/src/b2b133c5bba4f54a3bb48d6eab864c3b7106e5de/ide/ESPTool.gp#lines-108 location of the io0 Reset time problem, I manually pull down when it is normal to enter the download mode into the firmware burning.
2, I followed the tutorial in the readme to compile the firmware (ESP32), but the compiled firmware seems to be unable to load the library file written by myself, the basic code block is normal, only the library file has some problems, I guess it is because I compiled the firmware caused some problems in the process of loading the library file to ESP32, resulting in some variables not loaded correctly, but the firmware is compiled in accordance with the readme, but the firmware is not loaded correctly. But the firmware is compiled according to readme, but it works fine with the firmware burned on Microblocks platform, but not with the firmware compiled by myself.

Attached is the datasheet of WCH CH9102

Comments (29)

  1. C WEIB reporter

    CH9102X It can work with CP2102 pin to pin and supports drive-free, cheap price and stable performance, it is a very good choice

  2. C WEIB reporter

    My firmware burning process:
    1、0x1000 for smallvm/esp32/bootloader_dio_40m.bin
    2、0x8000 is the partitions.bin compiled by PlatformIO
    3、0xE000 is smallvm/esp32/boot_app0.bin
    4、0x10000 is the firmware.bin compiled by PlatformIO

  3. John Maloney repo owner

    I'm glad you want your new hardware to work well with MicroBlocks.

    stuck in Connecting ...

    It sounds as though the board is not responding when the RTS/DTR lines are manipulated to put the ESP-32 into boot mode. Does your board support that feature?

    To simulate that manually, you can ground pin GPIO 0 while resetting the ESP32. It might work to do that while MicroBlocks is attempting to download the MicroBlocks firmware. You'd need to get the timing just right.

    The MicroBlocks installer is designed to work with boards that support the RTS/DTR mechanism. One way to check that mechanism is to test your board with Espressif's esptool (https://github.com/espressif/esptool). If you can install firmware using esptool then it should be possible to get the MicroBlocks installer to work.

    the compiled firmware seems to be unable to load the library file written by myself

    Are you trying to load a library written in MicroBlocks or are you trying to link a C/C++ library into the virtual machine? If you attach the library, I can take a look.

  4. John Maloney repo owner

    If the VM you compiled works in general but is giving the error "Primitive not implemented in this virtual machine" then you may be using a new feature. Make sure that you check out the pilot branch of the repository to get the source code for the latest pilot release.

  5. C WEIB reporter

    Thank you for your reply, I'm sorry my expression is not very clear, in the hardware design has designed the automatic download circuit (RTS/DTR) I use the cp2102 when it can automatically download, do not have to manually pull down to enter the download mode, in esptool works fine. In CH9201X, the serial chip needs to pull down io0 to enter the download mode, but it can automatically download in flash_download_tool without pulling down io0.

  6. C WEIB reporter

    编译好的固件好像无法加载自己写的库文件

    Yes, I'm loading a library written in MicroBlocks and I seem to have some problems loading it into EPS32, it's only in my own compiled firmware that this problem occurs

  7. John Maloney repo owner

    In CH9201X, the serial chip needs to pull down io0 to enter the download mode, but it can automatically download in flash_download_tool without pulling down io0.

    It sounds like flash_download_tool uses a different mechanism that is not currently supported by MicroBlocks. Will your board have the RTS/DTR circuit for entering boot mode and resetting the chip?

    If the board does not have the hardware needed to support the esptool firmware install mechanism, then an option would be for users to to download the ESP firmware (https://microblocks.fun/downloads/latest/vm/vm_esp32.bin) and install it manually using flash_download_tool.

  8. John Maloney repo owner

    Yes, I'm loading a library written in MicroBlocks and I seem to have some problems loading it into EPS32, it's only in my own compiled firmware that this problem occurs

    Can you load the library into MicroBlocks when the board in not connected? Is it a very large library

    If you post a link to the library I can take a look.

  9. C WEIB reporter

    Will your board have the RTS/DTR circuit for entering boot mode and resetting the chip?

    Yes,board have the RTS/DTR circuit for entering boot mode and resetting the chip

  10. John Maloney repo owner

    This is the official download tool of espressif Theoretically it should be the same principle as esptool

    and

    Yes,board have the RTS/DTR circuit for entering boot mode and resetting the chip

    I think that means that the MicroBlocks downloading mechanism should eventually work because it also uses the same principle as esptool. It might just need some timing adjustments in the code that enters bootmode (e.g. exactly how long to assert RTS and DTR).

    In fact, it might be even simpler -- I might just need to add and entry for the new serial chip to this list:

        var vendorIDs = [
            { usbVendorId: 0x0403},     // FTDI
            { usbVendorId: 0x0d28},     // micro:bit, Calliope
            { usbVendorId: 0x10c4},     // Silicon Laboratories, Inc. (CP210x)
            { usbVendorId: 0x1a86},     // CH340
            { usbVendorId: 0x239a},     // AdaFruit
            { usbVendorId: 0x2a03},     // Arduino
            { usbVendorId: 0x2341},     // Arduino MKR Zero
            { usbVendorId: 0x03eb},     // Atmel Corporation
            { usbVendorId: 0x1366},     // SEGGER Calliope mini
            { usbVendorId: 0x16c0},     // Teensy
            { usbVendorId: 0x2E8A},     // Raspberry Pi Pico RP2040
            { usbVendorId: 0x303a},     // Espressif USB JTAG/serial debug unit
        ];
    

    Do you know the USB vendor ID for the serial chip you are using?

  11. C WEIB reporter

    Great!!! I know how to get the USB vendor ID, but the board is not around at the moment, so I may have to get it the day after tomorrow and get back to you, great, this will help me a lot with my board development!

  12. John Maloney repo owner

    Based on this page, the vendor ID is 0x1A86, which is already on our list. If you run MicroBlocks in a Chrome or Edge browser and click the USB icon, does your board appear in the list of serial devices? If so, then we are all set with the vendor ID.

  13. C WEIB reporter

    Yes, my board appears in the list of serial devices,It can be connected to Microblocks normally, and it works normally, but it just can't use Microblocks to burn firmware

  14. C WEIB reporter

    I made a query CH9102X the vendor ID is 0x1A86,the problem still exists, if I want to enter the download mode I still need to manually go to the drop-down io0,whether only some timing adjustments can be made in the code entering boot mode (e.g. asserting the exact timing of RTS and DTR).

  15. C WEIB reporter

    Hi,John

    I just tested modifying the reset time for RTS and DTS, and it works, and it works brilliantly.

  16. John Maloney repo owner

    Great that it can be made to work by modifying the delays!

    We can definitely fix this.

    However, since it retries this process 30 times, the milliseconds can add up. Could you try some intermediate values for those delays? Ideally, you'd identify the lowest values that work consistently, then we'd add some additional time to them to allow for component variation. I would change only one of the delays at a time. I'm guessing the second delay could be decreased substantially. (I can't do these experiments since I don't have your hardware.)

  17. John Maloney repo owner

    I tweaked the delays in Pilot release 1.1.85. Can you install the ESP32 firmware on your board with that version?

  18. John Maloney repo owner

    Is 1.1.85 working to install firmware on your board? I will assume it is unless I hear otherwise...

  19. C WEIB reporter

    Sorry John, I just saw the news, because recently there are some things, so there is no multiple computer testing, my side today after the test, reply to you here, thank you for your help

  20. Log in to comment