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

Problem accessing USB-host controller when RT-lib is running

Hi,

I'm having some trouble working with the usb-host controller of an AT91SAM9261 mcu. The CPU stops executing my code if I try to read from the usb-host (address 0x500000). When the mcu crashes it doesn't seem to be jumping to any of the exception-handlers and if I try using the debugger I get an error message that the debugger is "unable to halt the cpu", and then the Debug-message-window is flooded with error messages.

It seem to be related to the RL-RTX library since it seem to work better (it still crashes in certain cases) if I comment out the os_sys_init()-function and don't start the threads.

Does the RL-RTX-lib protect some memory areas or maybe overrides an exception vector or something that might cause this behavior?

I would appreciate any help or suggestions.

Best Regards
/Ake Forslund

  • RTX does not offer any memory protection. When you don't call os_sys_init you basically do not start any task in your application.

    I am suprised that your program works after that at all. This indicates that you have still some code in the main function. However after os_sys_init the main function stops executing and the task stated as parameter is started instead.

    Take a look to: www.keil.com/.../rlarm_ar_your_first_app.htm

  • When I comment out the os_sys_init()-function my application does not start, but it does continue to execute after i read the register in question.

    Basically if I make an endless loop in my main()-function where I constantly read the register and switch a led on and off I can debug the application and see with my eyes that the LED is toggling. If I instead start the RTX-kernel, starts a task and have that task run an endless loop reading the register the cpu seems to freeze (does not go to an error-handler) and the debugger looses it's connection to the cpu.

    It is really weird since it seems like 0x500000->0x5fffff does not work but address 0x600000 (the LCD-controller in this mcu) works just fine.

  • Update:

    I have now been able to read the register from a task dedicated to this purpose, but it still won't work from the tasks in my application. Could this perhaps be a stack-issue?

  • Update: I seem to be completely barking up the wrong tree here. The times I successfully read the register, seem to have been phony readings. It seems like the critical line of code was removed by optimization, so I can't blame RTX.

    I'm curious to why I get this crash when running the line:

    test = *((long *)(0x500000));
    

    Any help or suggestion is still appreciated!

    Best regards
    /Ake Forslund

  • Ake,
    Are you absolutely sure that the controller crashes when you read that memory? have you verified it with a debugger? did you watch the disassembly window at the time of the crash? what is it that you do just before it goes wrong? can you simplify/remove it?

  • I am almost positive, I have verified using LEDs and with debugger. When I single step past this line the debugger shows me an error message saying that it can not halt the cpu.

    My test function should toggle the red and green LED on my board, but it freezes as soon as I try to read the register.

    my test function:

    int main(void)
    {
      init_io();
    
      AT91C_BASE_SYS->PMC_PLLBR = 0x01483F0E;    //18.4/14 * 72 (USB-Host clk is PLLB / 2)
      AT91C_BASE_SYS->PMC_SCER  = 0x00000040;
      AT91C_BASE_SYS->PMC_PCER  = 0x00100000;
    
      while(1)
      {
        AT91C_BASE_PIOA->PIO_CODR  = RED_LED;
        AT91C_BASE_PIOA->PIO_SODR  = GREEN_LED;
        test_delay();  //0.5 sec
        test = *((long *)(0x500000));  //It fails here
        AT91C_BASE_PIOA->PIO_CODR  = GREEN_LED;
        AT91C_BASE_PIOA->PIO_SODR  = RED_LED;
        test_delay();  //0.5 sec
      }
      return 0;
    }
    

    If I check the assembly for the line in question I get

       114:     test = *((long *)(0x500000));
    MOV       R0,#0x00500000
    LDR       R0,[R0] <-this is where it seem to crash
    LDR       R1,[PC,#0x0020]
    STR       R0,[R1]
    

    If I do the same with address 0x600000 it works fine.

  • Ake,
    Are you using some exotic hardware? something? I had a quick look at the user manual, it does not seem as if you are doing something wrong.

  • The hardware isn't very exotic, and further testing has shown that there is problem with the initiation of the clocks for the host-controller (When reading the status registers none of the USB-host related clocks are reported active). I'm doing something wrong or maybe not setting a register that I should be setting. I have contacted the support at Atmel and they has sent me contact information for a person that has worked with the same hardware as I am working with now, hopefully he has some insight into this problem and can tell me what I'm doing wrong.

    Thank you for your help.