This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

mixing C and Assembly


Hello,I'm using the soft-core Cortex-M0,and keil uvision 5,
I have initialized the registers used for my ADDER : 0x59000000--->059FFFFFF
and run simulation using vivado simulator
when i tried that with assembly the simulaion worked correctly,but if i tried to add c code with the assembly it doesn't work:
this the code:
-----------------------------------------------------------------------------------------


; Vector Table Mapped to Address 0 at Reset

                                                PRESERVE8
                                THUMB

                                        AREA    RESET, DATA, READONLY
                                        EXPORT  __Vectors
__Vectors                       DCD             0x0000FFFC
                                        DCD             Reset_Handler
                                        DCD             0
                                        DCD             0
                                        DCD             0
                                        DCD             0
                                        DCD             0
                                        DCD             0
                                        DCD             0
                                        DCD             0
                                        DCD             0
                                        DCD     0
                                        DCD             0
                                        DCD             0
                                        DCD     0
                                        DCD             0

                                        ; External Interrupts

                                        DCD             0
                                        DCD             0
                                        DCD             0
                                        DCD             0
                                        DCD             0
                                        DCD             0
                                        DCD             0
                                        DCD             0
                                        DCD             0
                                        DCD             0
                                        DCD             0
                                        DCD             0
                                        DCD             0
                                        DCD             0
                                        DCD             0
                                        DCD             0

                AREA |.text|, CODE, READONLY
;Reset Handler
Reset_Handler   PROC
                GLOBAL Reset_Handler
                ENTRY
                                IMPORT  __main
                LDR     R0, =__main
                BX      R0
                ENDP

                            EXPORT func
func            FUNCTION
                 ENDFUNC


                                ALIGN           4
                        END



-------------------------------------------------------------------------------------
and the code C :

#include <stdlib.h>
#include <stdio.h>
#include <rt_misc.h>
#define AAA     (*((volatile unsigned long *)(0x59000000UL)))
extern void func_x()
{
        unsigned int volatile * const port1 = (unsigned int *) AAA;
         int a = 0x11111111;
  *port1 = a;
                }

int main(void) {
        func_x();
return 0;
}



Parents
  • Consider using the debugger, turn off "run to main", and step through your code one instruction at a time until you understand what's wrong. Suggest a Hard Fault handler so you can see when it fails, and a routine for the other unused vectors to use instead of zero.

    Make sure you have correctly defined the memory for the linker, and that your stack points to usable RAM.

Reply
  • Consider using the debugger, turn off "run to main", and step through your code one instruction at a time until you understand what's wrong. Suggest a Hard Fault handler so you can see when it fails, and a routine for the other unused vectors to use instead of zero.

    Make sure you have correctly defined the memory for the linker, and that your stack points to usable RAM.

Children
No data