wagiminator / MCU-Flash-Tools

Simple ISP Flash Tools for various Microcontrollers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RTS DTR auto boot enter?

NoNamedCat opened this issue · comments

Hello again.
It is possible to implement this type of schema for the boot-loader in the code?

image

I'm designing a new board for the PY32F002A micro-controller, wondering about using the CH340X as a USB-Serial communication IC for the board. If this could be implemented, I think is a no brainer to choose that IC instead of the CH340N (That doesn't have DTR or RTS)

This work well with the ESP8266 or the ESP32.
The EspTool (The program to burn the firmware for the ESP series) handle the reset line and the boot pin.
Do you think that is possible to implement this?

In PySerial you can directly set the control lines, e.g. "self.rts = True" (which means LOW on the RTS pin). So you can customize the software the way you want. By default RTS and DTR will be pulled low as soon as the communication begins. Keep in mind that this way of connection WILL cause problems, if you want to use it also for normal serial communication using a different serial monitor. By the way, the CH340N has an RTS pin. Take a look at the CH340E, which is quite small and has RTS, DTR and an LED pin.

Maybe adding a contraption based on transistors will help with this issue?
Like the DEV boards for the esp32 micro-controllers do?
Something like this:
Screenshot_2023-11-09_15-33-41

The CH340X is designed for not needing that transistor contraption...
That's why i think about using that usb-serial IC.
Please see chapter 5.3. DTR and multi-mode MCU download

Of this datasheet: https://cdn.sparkfun.com/assets/5/0/a/8/5/CH340DS1.PDF

BTW... I noted your MCU boards repository. I really like it and that's why I'm designing a new board. I am really grateful for you sharing all of this.

Screenshot_2023-11-09_15-46-27

This looks like a clever solution. Just give it a try!

I added the additional control functions of the CH340X for BOOT0 and nRST according to the datasheet, but I can't test it at the moment. If you have implemented your board, please give me feedback. At the same time, I ordered a few CH340Xs, but I probably won't get around to experimenting with them until next year.

Hi! I really appreciate this. I'm working on the design first. I think I will finish it this weekend. I work in a company that buys PCBs from jlcpcb and normally I wait till the day that they buy many boards to not pay a cent for the shipping. So I don't know when I will get the boards in my hands. I really appreciate your work with all of this MCUs. If you want the design that I'm working on please just let me know. The board is double sided but the components are only on one side(to use the service of jlcpcb for putting all the components on the board for me). You can select the working voltage with a jumper (3.3v or 5v) it has an onboard 3.3v regulator, USB type c with 5.1k resistors so it can work with USB type c to USB type c cables to trigger the host mode.

I am very curious already!

In the zip file you can find the schematic, KiCad project (if you want to modify it), many .zip files containing all the gerber files for production in many PCB houses (jlcpcb, pcbway, fusionpcb, elecrow). It also have an interactive BOM...

I can do a panelization of the board for you if you want to make multiple boards. Yoy can fit many of this tiny boards on a 10cm * 10cm board (8 or 12 i think will fit in that space) So if you order 5 boards of 10* 10 you will get 40 minimum.

I hope you like this.

Cool! I made some changes to my DevBoard as well and gave an order to JLCPCB. Let's see when everything arrives and I find the time to try it out.

Hi, CH340X and board are here. I was able to do a few tests. ISP software works - so far so good. Apart from that, unfortunately the problems I feared arise. If you try to use the CH340X as a "normal" USB-to-serial converter with any serial monitor, the PY32 will be reset because, as usual, the RTS pin is automatically set to LOW when data is sent. Second problem is that despite the pulldown, BOOT0 is pulled to HIGH by default by the CH340X. A normal reset using a button is therefore not possible - you always end up in the bootloader. I currently don't know how to work around the problem...

Hello Wagiminator. Maybe we can add some components to make the thing works. Can you share the schematic of your design so I can analyze it?

maybe with some capacitors and transistors we can make it works

Also... Do you have a logic analyzer or some scope that can help us to debug the DTR and RST lines?

Yes, I have a logic analyzer and I also used it here. You can certainly create a solution with additional components, but of course they make the whole thing more complex and then they also have to fit on the board.

A resistor and capacitor on the BOOT0 will add a delay in the DTR of the CH340X. It may be the solution on the boot state of your board?

so... If you add that, you need to make a delay in time on the code for programming the device. You need to put the DTR line in the level for flashing state. Then you add a delay so the capacitor will reach the logic level of the boot state. Then you reset the MCU. The solution is two small components. What do you think?

That won't help. The situation looks like this: If the board is connected via USB, then RTS and DTR are high. If I open the connection to the CH340X for example with CuteCom, RTS and DTR are immediately set to low and remain low until I close the connection.

I suspect that the CH340X is pulling the DTR line hard to VCC (open-source), if I overpress that there will probably be a short.

Can you try it with the serial debugger in Arduino IDE?
I think that the software that you are using is more focused on communicating with modems and other kind of hardware. Please give it a try and tell me how it works please.

Also... Here is a link explaining the CH340X IC:
https://www.youtube.com/watch?v=CGLHfyW0rYE

Have you tried to connect T-NOW to CTS with a 4.7K resistor instead of using the 4.7 pulldown resistor on the T-NOW?

It's the same with the Arduino IDE (at least on Linux, if that has any influence). Thanks for the video link. I think it works great if you make a programming device with the chip. However, the problems remain for a full on-board solution. Connecting the resistor between DTR and CTS makes no sense here. DTR is then only set push-pull instead of open-source. This certainly makes sense with other MCUs.

I feel sad about that. Sorry to hear that the solution didn't work.

Yes, that's a real shame. It would have been a really elegant solution. Well, maybe I can think of something else.

If DTR were LOW in its default state, I would immediately have a simple solution. It's really not clear to me why this is solved this way with the chip.

Maybe if you put a capacitor like a DC filter on the rts line? I don't want to lose hope :c

This would be the easy solution ... if DTR were LOW on default.

Hello again Wagiminator. Hope you are fine.
I want to tell you about the new repo of HalfSweet (the creator of the PY32DUINO).
She designed a board for the PY32F030 MCU and she have done a solution based on transistors like this:
Screenshot_2023-11-28_17-10-39

I think that you can replace the mosfets for NPN transistors like the 2n2222 or 2n3904

it's the same circuit that i posted before_
image
but it uses the third transistor to negate the BOOT0 state

The ch340x function and behavior is like having the two first transistors, do you think that if we put the third transistor only on the boot line to negate the state, we can manage to make the board work?

When I look at the behavior of the CH340X, I come to the conclusion that the only difference to the CH340E is that the DTR signal can be ouput on a pin if necessary. This means that the circuit with the transistors is necessary here if you want to use the chip also as a USB-to-serial converter and not just as a programming device.
In principle, you can also build the circuit with BJTs instead of MOSFETs. You then need resistors for the base. The body diode of the MOSFETs might also have to be taken into account.

If I make the board design with all of this stuff, I will post it on this topic. Are you still interested? It will be my pleasure to give you that

Oh yes, I'm looking forward to it.

I finish the board design. I grabbed the transistors for the boot pins from the repo above. Can you tell me what do you think about it? There is a space left on the board that I can use for some leds on the TX and RX pins (Like the Arduino boards).
All the passive elements (Caps and Resistors) are 0805, smaller ones are difficult for me.
If you want some personalized silkscreen I can do it for you (And this repo)

PY32F002

Nice Logo! Is there a reason why you used CTS instead of DTR? I don't think that will work.

There might be som problems with the CH340X if you select 3V3 as MCU VCC. If you power the CH340X with 3V3 on the VCC pin, you should also power it with 3V3 on the 3V pin, I think. You can solve that with a permanent connection of the 3V pin to +3.3V of the LDO.

Please take a closer look at the MOSFET circuit and compare it with that of HalfSweet. How do you want to pull the NRST pin to LOW?

Tks for the hints. I will correct those and share the design with you.

I will need to redo many things with the changes that you proposed. But is very late here right now. Tomorrow I will continue to design the board. If you like my logo... I can design one for you if you want.

I still believe you have to swap PF2 and PA6 as well as DTR and RTS at the MOSFET circuit.

If you have some room left on the board, some 100nF capacitors for the power pins of the CH340 and PY32 will make the whole thing a little more stable, although it certainly works without it.

TX-RX
TX-RX2
Ok. I swapped the DTR and RTS lines and added 100nf caps on 5v and 3.3v lines. But I don't understand why we need to swap the RX and TX pins on the board.
With serial ports you need to connect the RX pin (on the serial ic) to TX pin (on the MCU) and the TX pin (on the serial IC) to the RX pin (on the MCU).
The TX pin on the CH320 transmit, and the PY32F002 PA3 receive
The RX pin on the CH320 receive, and the PY32F002 PA2 transmit.

I will test if the TX and RX are fine with my old design and will make the changes if the lines are truncated on the design.
Tks a lot again Wagiminator.

The RX and TX lines works fine for me.

I have a problem with the current design. I want to make a panelization (Array of boards) of the design. The USB port and the buttons for reset and boot crash in the panel. The idea is to make a panel of 3*2 on the standard size of the JLCPCB. If the board works I think that we don't need the buttons in the board. Do you think that we need the buttons?

I never mentioned TX/RX. You should swap PF2 (NRST) PB6 (BOOT0) on the MOSFET circuit (see HalfSweet's circuit).

Well, if it works you don't necessarily need the buttons. If necessary, you can connect some via the pinouts.

I'll probably have to adjust the ISP software...

I'm sorry for the spam. This design would not exist if it weren't for you. Tks a lot.

Actually it's a very simple question...the condition for py32 to enter the bootloader is very simple, just have the boot0 pin high at reset. So we may easily find a similar schematic online.
图片
But there is a problem, when we switch the serial port on and off, the level of DTR and RTS may not be fixed, which may cause us to enter a different mode than expected by mistake.
And in the Arduino IDE, DTR and RTS are set to true when the serial port monitor is turned on - a very bad design, and to avoid this problem, back when I was designing the Air001 development board I included the An ESP32 autodownload-like design using two BJT/MOS to implement a hardware heterodyne circuit, which we can see in https://gitee.com/openLuat/luatos-broads/tree/master/broads/Air001-Board at the time.

Of course there is a slight problem with this circuit, which means we can't control the levels of boot0 and RST at the same time, so we compensated for this by connecting a capacitor in parallel to GND for both boot0 and RST, and performing pull-downs and pull-ups according to the needs of the running app.

Alternatively, you can view a typical PY32F030 development board design https://github.com/HalfSweet/PY32F030K28U_Arduino_Nano

At AirISP, I implemented the automatic download logic for the relevant circuits

You are a FullSweet ;) tks a lot for sharing your knowledge with me. Can I share this conversation with Wagiminator so he can design his board too?

You are a FullSweet ;) tks a lot for sharing your knowledge with me. Can I share this conversation with Wagiminator so he can design his board too?

Of course, our sessions are open and we can have discussions together if we can

That looks promising.