-
-
Notifications
You must be signed in to change notification settings - Fork 87
[Bug] Insufficient initialization of SCI leads to not all desired UART baudrates being possible to select #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I see you are using R_SCI_UART_BaudCalculate. I could not communicate with the device communicating at 1Mbps, so I tried to capture the transmitted data with another serial monitor separately and got bit corrupted data. I just noticed that err_rate is supposed to handle 1000 times the value, but I thought that if err_rate=5, it would be considered 0.005%. |
Please let us know what you find, meanwhile I'll close this issue as it's root cause was a misunderstanding 😉 |
Is it too early to close? I tried initializing Serial1 with the following baudrates Please try to evaluate the actual performance of all of you. thanks |
Hi @mukyokyo , |
It did not change when we actually set 3000 assuming 3%. |
I will just note what I have learned somewhat. It is clear from the return value of R_SCI_UART_BaudCalculate that the erroneous handling of the digits in err_rate. Second, even if R_SCI_UART_BaudCalculate returns FSP_SUCCESS, it does not appear that R_SCI_UART_BaudSet sets the baudrate to the expected baudrate. Finally, the previous list of baudrates only describes the behavior at those values. The results are somewhat troublesome so far. |
Since the only way to determine whether the actual baud rate is correct or not is to suspect the value held in the variable. static int ind = 0;
const uint32_t baud_list[]={9600,57600,115200,230400,250000,460800,500000,600000,700000,800000,900000,1000000,1500000,2000000,3000000,4000000,6000000};
fsp_err_t err;
const bool bit_mod = true;
const uint32_t err_rate = 3000; // Meaning 3%
baud_setting_t uart_baud;
if (++ind > (sizeof(baudlist) / sizeof(uint32_t) - 1)) ind = 0;
err = R_SCI_UART_BaudCalculate(baud_list[ind], bit_mod, err_rate, &uart_baud);
if(err != FSP_SUCCESS) {
Serial.println("BaudCalculate error");
} else {
// err = R_SCI_UART_BaudSet(&uart_ctrl, (void *) &uart_baud);
Serial.print(" bgdm=");
Serial.println(uart_baud.semr_baudrate_bits_b.bgdm);
Serial.print(" abcs=");
Serial.println(uart_baud.semr_baudrate_bits_b.abcs);
Serial.print(" abcse=");
Serial.println(uart_baud.semr_baudrate_bits_b.abcse);
Serial.print(" cks=");
Serial.println(uart_baud.cks);
Serial.print(" brr=");
Serial.println(uart_baud.brr);
Serial.print(" mddr=");
Serial.println(uart_baud.mddr);
Serial.print(" semr_baudrate_bits=");
Serial.println(uart_baud.semr_baudrate_bits);
} I tentatively tried "const bool bit_mod = false" and now I can generally communicate with the list of baud rates in the previous source (I haven't looked at the actual error rate). |
The most likely possibility is a bug in R_SCI_UART_BaudCalculate. Since the condition has been identified, the fix is a simple matter. However, since we will not be taking care of fsp here, we will pass it to the fsp side. Finally, I leave it here to note that the baudrate error rate must be specified in multiples of 1000. thanks |
I have come up with a cute solution that is not affected by the fsp update and I present it to you. I have actually confirmed that the problem goes away. err = R_SCI_UART_BaudCalculate(baudrate, bit_mod, err_rate, &uart_baud);
if (uart_baud.mddr==0) err = R_SCI_UART_BaudCalculate(baudrate, false, err_rate, &uart_baud);
err = R_SCI_UART_Open (&uart_ctrl, &uart_cfg); Basically I expect bitrate_modulation to be true, so please don't think that setting it to false all the time will solve the problem. |
Hi @mukyokyo ☕ 👋 Thank you for your investigation as well as sharing the results. Would you mind to prepare a PR for it? |
The real purpose is different. In the meantime, I will leave the PR of this baudrate flaw to you. thanks |
Hi @mukyokyo , |
The uart HAL/Common Stacks was set in this library, but it assumes that DTC will be used (which doesn't seem to work in practice). The commonly used baudrate of 115.2 kbps or lower is still reasonably functional in its current state. Am I the only one who is not satisfied with this level of baudrate? |
As for the missing received data, it is due to the interrupt priority, as I suspected. SCI generates an interrupt for every byte, so at high baudrate the load is very high. I am not involved in the design of this library, but it is hard to come up with a good idea if the use of DMA is restricted. |
USB: implement PluggableHID Former-commit-id: 309e074
Since you are using fsp, I would recommend using R_SCI_UART_BaudCalculate to minimize the baudrate error.
Currently, the baudrate is initialized with a large error rate, and the R4 is not able to handle the baudrate that the AVR was able to handle.
The text was updated successfully, but these errors were encountered: