-
Notifications
You must be signed in to change notification settings - Fork 73
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
Self-compiled project works not reliable #29
Comments
Hello together, after some more testing I finally got it to work.
It would be interesting to find the root of the problem. Let me know if you're interested in further investigation, I'm willing to help if you like ! Best regards, |
I am working on another project of STM32. I think compile option does makes difference for USB performance. In the mean time there is known issue regarding the resistor used on the board (should be 1.5K not 10k). For me it works better if I hook up with a USB 2.0 hub. |
@usbcnc Did you mean the pull resistor between USB D+ and VDD ? |
@radiolee Yes. The soldered resistor is 10K. It will work on some PC but not work on the others. |
@usbcnc Thanks! My stm32f103c8t6 mini board is on the road. I'll check it when I get it. |
@usbcnc I got the board with 1.5k pullup res. |
I got my board with 10k pullups and changed them to 1.5k but the problem remains the same. Regards, |
I am not expert of tool chain. I use what works for me for now. If one works and the other does not , I can assume the other one has a bug or so. If you really want, disassemble the elf and find the difference. |
I have noticed in the past some compiler will optimize differently the following code. |
O3 might work better than optimize for size. |
I do have latest coocox installed but not the latest tool chain. I still prefer to use older ide since I get used to it. Do not find need to have to use the latest one. |
Thanks for ur reply. I'm still use old version |
I don't use the serial interface, but USB instead. So in my understanding this should not be a problem.
As I wrote in my first post I already tried different optimization levels without luck ... |
I guess @usbcnc point out While(some flag!=true) in serial.c maybe differently optimized by latest gcc, and the point is in interrupt routine. If some diff in interrupt, it may makes random issues. |
Try to disable compile option and compare the result between the two compilers. I do not have installed the latest tool. |
I'd love to find the root cause of the problem, but I think my knowledge is not enough for that. |
It should related to the serial port code a(USB). You can try to user real serial port (not USB VCP) to see if both tool works the same. |
Today I could narrow down the problem and @usbcnc you're right: The problem seems related to the USB VCP code. Real serial port (using an external USB-RS232-converter from FTDI) works fine. So it really seems a compiler optimization problem. I try to further isolate the problem, but this will take some time. |
Have you tried O3? |
Yes I tried -O3, it doesn't work either. The problem seems to be the -fschedule-insns2 optimization flag which is automatically enabled at -O2, -O3 and -Os. This leads to the question, what's the root of the problem: |
I would check the code generated for serial.c and usb_endp.c.
|
main.c has no issue. As I said in serial.c and usb_endp.c |
Sorry, I noticed that myself and here are the correct files again: serial-not-okay.asm |
I think there is a bug in the compiler. Wrong order. Should swap the lines. The c code is serial_tx_buffer_head = next_head; Which to me the OK one generate the right code. |
In the above code, the order is VERY important, if the order is wrong the result can be unpredictable. |
Try change to this and see if the problem is fixed. serial_tx_buffer_head = next_head; |
By disabling the IRQs the program works fine now. Thanks for your help ! Maybe it's a good idea to update the git sources ... |
The original source is good. But the optimization has issue not the code itself. |
Original GRBL is carefully written and these two lines have a good reason to be in this order. If compiler changes the order, that means it cannot be trusted. Original code says "// Store data and advance head" |
https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads why not try 2017q4 or other version to check if the problem fixed? |
I just tried the new gcc (2017q4) and the problem is still the same. And one more question just for my understanding: |
@lakeroe I think disable irq just a debug code, bypass something to test. I really don't know what's different use -fno-schedule-insns2 so can't help. |
https://groups.google.com/forum/m/#!topic/gnu.gcc.help/hZ5hArJ3VSU |
@lakeroe, I do not know your educational background. If you look at the usb_endp.c which use the flag (in ISR), you should know this order is very important. Disable the IRQ means no interrupt will happen between two lines and the problem will not happen. The problem will happen ONLY if the interrupt is happening between those two lines. |
I've learnt programming microcontrollers in C 25 years ago and apart from some hobby projects my knowledge is quite basic. I'm currently working as an electronics hardware developer (mainly microcontroller circuits). Thanks for the explanation, I think I understand the problem now. Regarding the thread you mentioned above: Anyway, my solution is to use your unchanged code and add the -fno-schedule-insns2 flag. |
I have read and I do not believe this is a bug for compiler. It just means in this case, this optimization needs to be disabled for those two lines. I think there is a better way to disable this option only for those two lines. -fno-schedule-insns should go with -fno-schedule-insns2. They both do so called "instruction scheduling". |
By adding "attribute((optimize("-O0")))" it should be possible to completely deactivate optimizing for a specific function, but I think that's not exactly what we want ... |
@lakeroe that will do the trick and should be used. It is better than disable the IRQ. |
Just for your information: Do you think that should be added to your source ? |
@lakeroe Yes I think so. |
Just for your information: __attribute__((optimize("-O1"))) works also fine |
Hello USBCNC,
I flashed an older hex file you provided here on a blue pill STM32F103C8T6 board, installed ST's VCP driver and did a first test.
I streamed a pretty big g-code file (860.000 lines, running time ~2hours) using bCNC -> this works without a problem.
However, the same test using a self-compiled file only works for a few minutes but after some random time (between 5 and 15 minutes) it hangs.
I already tried different compiler options and optimization levels but can't get it to work reliable.
A next test is to use an older compiler. I currently use 6.3.1-2017q2 and I think you used 4.9-2015q3 as I saw here.
Do you have any further ideas ?
I'm interested in a stable and reliable GRBL STM32 port, so any help is highly appreciated.
Thanks and best regards,
lakeroe
The text was updated successfully, but these errors were encountered: