Reputation: 151
EDIT: here is a minimal working example of code I can't manage to debug. I found a solution for the compilation problem.
Solution for compilation problem: Add .syntax unified and it stops complaining about the it blocks.
Still not sure about the flags, though
I'm having a bit of trouble with ARM assembly. I've got an STM32F769NI Discovery board (which is having a Cortex M7).
I've got a program that is making an LED blink and it works fine if I flash it with the ST Utility thingy and I can also run it with the same application.
However, I'm having a bit of trouble with the compiling. As soon as I introduce anything relation to conditional instructions (cmp, it blocks and BL{cond}), things go south but I also don't really know what parameters I'd actually need for compiling the assembly code. Currently, I'm using
gcc -mthumb -mcpu=cortex-m7 -mfpu=fpv5-sp-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -ffast-math -c -g
I didn't manage to find any flags for as which seems like the more logical option for assembly code.
For linking, I use
ld -T script.ld
It seems to work for the program I'm currently having but I can't compile anything with conditional execution.
If I simply add
cmp r0, r1
bleq wait
It says src/main.s:59: Error: Thumb does not support conditional execution
Ok, cool. So let's add an it eq
above the two instruction because that's what you should do for thumb, right?
Then I get a bunch more errors
src/main.s:60: Error: Thumb does not support conditional execution
src/main.s:62: Error: incorrect condition in IT block -- `b loop'
Line 60 is the it branching and line 62 is the next instruction (empty line between them).
So, even though my code compiles, something seems to be very wrong. wait
is a label that exists. The code is otherwise working. The LED is blinking along like it should.
Now concerning debugging. I tried OpenOCD and I tried ST-Utility.
With OpenOCD, flashing the chip via GDB fails every other attempt. Also, sometimes, if I start GDB, it's not halting at the start label but at some garbage address. I also never figured out how I can simply run the program with OpenOCD. I connected the board via tar remote :3333
With the ST-Utility, flashing via GDB works every time but I can't flash with the st-flash application. It throws this error:
2018-01-04T10:09:22 ERROR C:\Users\Jerry\Desktop\stlink-master\src\flash_loader.c: flash loader run error
2018-01-04T10:09:22 ERROR C:\Users\Jerry\Desktop\stlink-master\src\common.c: stlink_flash_loader_run(zx) failed! == -1
stlink_fwrite_flash() == -1
I use tar extended-remote :4242
to connect to the board via the st-utility.
ST-Utility also ignores breakpoints. I can run and kill the program (can't do that with OpenOCD) but if I set a breakpoint and use "run", it ignores the breakpoint. If I do continue, it hangs. I could do that with OpenOCD.
Flashing, running, halting and stepping through the program works perfectly with the ST-Link software.
I'm using the built in ST-Link/V2.1.
I have my code and any config files in a GitHub Repository here. There is also a bat for OpenOCD so you can see the parameters I use (I only use -m for the st-util).
I know that there are IDEs I could use that would take that work off of me but I don't want to deal with eclipse. I'm quite happy with Visual Studio Code and I'd like to keep using it.
I started GDB from console and not inside Visual Studio Code.
Edit: I just realised I actually have conditional branching for my wait function. This works but if I add conditionals somewhere else, it doesn't work... I don't know why though.
Upvotes: 1
Views: 1486
Reputation: 71576
08000000 <wait-0x8>:
8000000: 20001000
8000004: 08000016
the vectors should be orred with one, the lsbit set. adding code to indicate this is a thumb function label
.thumb_func
_start:
fixes that problem
08000000 <wait-0x8>:
8000000: 20001000
8000004: 08000017
perhaps that is the only issue, perhaps there are others.
I recommend your "isr", (vector table) gets several more entries just have them go to an infinite loop.
.section .isr_vector
.word 0x20001000
.word _start
.word hang
.word hang
.word hang
.word hang
.word hang
.word hang
.word hang
.word hang
.word hang
.word hang
.thumb_func
hang: b hang
.thumb_func
_start:
that way since you are trying to use a debugger if this were a prefetch abort, or undefined instruction (gets an abort uses the "address" at an offset in the table which is actually thumb code, launches off into the weeds somewhere and hangs eventually) you have half a chance of tracking it. you can make a separate infinite loop for each vector if you do end up in the infinite loop.
In the future please post the example in the text of the question not a link. For example if you modify the code at that link at all, even to fix whatever is broken, you have now ruined this question as being useful to others.
Perhaps even now as I write this you have already fixed it? If so either fix the question to cover the history of the issue and fixes, or delete the question all together.
Upvotes: 0