msalau / rl78flash

Tool to program RL78 MCUs via serial bootloader

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not able to program (no response from microcontroller?)

bicyclesonthemoon opened this issue · comments

I am not able to use rl78flash for programming a device with a 104jg microcontroller.

2.b:~> rl78flash -ivvvvd -m3 /dev/ttyS0
Open port: /dev/ttyS0
Using communication mode 3
Turn MCU's power on and press any key...
Send 1-byte data for setting mode
send(1): 3A
recv(1): 3A
Send "Set Baud Rate" command (baud=115200bps, voltage=3.3V)
send(7): 01 03 9A 00 20 43 03
recv(7): 01 03 9A 00 20 43 03
recv(0):
FAILED
Initialization failed
Close port

It looks like the microcontroller is not responding.
That's exactly the same thing that happened here:
#6
In that case the problem was unconneced reset.

So I verified my circuit that it is electrically correct and it is.
This is how the signals look like (reset and tool0):
sds00001

And this is my circuit:
flsch

It's made after the rl78s-hw.png, but it has switches for selecting mode and power, an sp3232 chip and a 3v3 stabilizer. Powered from an usb cable.
I also have a second copy of this circuit made on a breadboard, without the switches. It's in mode 3. It doesn't work either.

It's also not the case of damaged microcontroller or device. I have access to several boards with a 104jg. None of them can be programmed with rl78flash but they all can be programmed with an E1 using the same cable.

So is the software doing something wrong? Like resetting incorrectly? timing? whatever?
Or maybe I'm using it wrong somehow?

Thanks in advance,
B

Hi @bicyclesonthemoon

The wave diagram looks good. The tool have send everything that is required by the protocol, but received no answer from the MCU (at least it is not shown on the diagram).

Do you really have to use the -d option? It is required only if utilize RESET pin as a GPIO. If this is not your case, please try without the option.

Since you have full control over the schematic, you can also try 2-wire UART mode (mode 2 and 4).

One more option to try is to increase delay after de-assertion of RESET.

Regards,
Maksim.

Thank you for the answer.
The -d option was not needed but it couldn't have broken anything.
2-wire mode is not something I would want to use because the device I'm trying to program has the txd and rxd lines connected to some additional circuits.

The increasing of delay after reset helped.
I increased it until it started working at 500. (Edited to add: on Windows I had to increase this to 1000).

where did the original value of 10 come from?
I have seen that the E1, for example, waited 3ms after de-asserting reset.

Also, I wonder, did nobody have problems with this before?

Unfortunately I still cannot program.
It gets stuck on this:
D:\b\rl78flash>rl78flash.exe -ewcvvv COM1 ex.srec
Send 1-byte data for setting mode
Send "Set Baud Rate" command (baud=115200bps, voltage=3.3V)
OK
Frequency: 32 MHz
Mode: full-speed mode
Send "Reset" command
OK
Send "Get Silicon Signature" command
OK
Device code: 100006
Device name: R5F104JG
Code flash size: 128kB
Data flash size: 8kB
Firmware version: 3.03
Erase
Send "Block Blank Check" command (range=000000..0003FF)
OK
Block is empty
Send "Block Blank Check" command (range=000400..0007FF)
OK
Block is empty
Send "Block Blank Check" command (range=000800..000BFF)
OK
Block is empty
Send "Block Blank Check" command (range=000C00..000FFF)
OK
Block is empty
Send "Block Blank Check" command (range=001000..0013FF)
FAILED
Block Blank Check failed (001000)
Read file "ex.srec"
Write
Program block 000000
Send "Block Blank Check" command (range=000000..0003FF)
^C
D:\b\rl78flash>

It just gets stuck and doesn't do anything.

The end of communication looks like this:
capture
Here is my full capture:
serial.txt

Here is the result of rl78flash.exe -ewcvvvv COM1 ex.srec:
log.txt

This seems to be the problem:
Send "Block Blank Check" command (range=001000..0013FF)
send(12): 01 08 32 00 10 00 FF 13 00 00 A4 03
recv(12): 01 08 32 00 10 00 FF 00 00 A4 03 02
recv(2): 01 1B

0x13 is sent but not received. It repeats every time.

Hi @bicyclesonthemoon

The increasing of delay after reset helped.
I increased it until it started working at 500. (Edited to add: on Windows I had to increase this to 1000).

Thanks! I'll double check manual/datasheet for limitations and fix this.

Also, I wonder, did nobody have problems with this before?

I don't remember where it came from, but it worked for me and devices I have. Possibly the issue with out-of-spec delay was hidden by OS scheduler.

0x13 is sent but not received. It repeats every time.

Does this happen on Linux too?
I have only 'small' MCUs at hand (up to 64k of flash), so I had no chance to verify the tool with larger memory space (your device has 128k of flash).

Also there is a bug in line https://github.com/msalau/rl78flash/blob/master/src/main.c#L230
It should be
rc = rl78_erase(fd, code_size, data_size);
The fix will make it fail earlier: right after failed erase.

Thanks for reporting. I'll investigate the issue with 0x13.

Maksim.

Does this happen on Linux too?

I will check this later. I use Linux at home and Windows at work.

The fix will make it fail earlier: right after failed erase.

Indeed. Now it fails after the erase and does not get stuck.

Please, try the fix-issue-8 branch.
It has 3 fixes (compared to master):

  • Increase delay after reset for G10 2ms (min 1ms);
  • Increase delay after reset for G1x 3ms (min 1ms + 723us);
  • Check return code of the erase function;
  • Explicitly disable XON/OFF flow control on Windows.

The last one, I hope, should fix the issue with missing 0x13.

I can confirm the fix.
I was able to successfully program the microcontroller on Windows.
I will check it on Linux later.

Edited to add:
It works, on GNU/Linux too.
Even just the delay increase is enough to make it work on this system.

Hi @bicyclesonthemoon
Many thanks for feedback! I've merged those changes to the master branch and created a new release: v0.5.5

Best regards
Maksim