Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
13 years ago

Nios II hanging/crashing on PIO write?

I'm using a DE0-Nano board with a design which includes a NIOS II processor with a PIO module to flash the board's LEDs.

No problems there - processor works, LEDs flash, jolly good.

But, I then did the following:

- Added a second PIO, 24-bit width output-only, and connected this to a custom hardware module in the project bdf

- Added a third PIO, 1-bit width input-only, with interrupt enabled, and connected this to a custom hardware module the project bdf (a clock signal).

I made no changes to the NIOS II code, and so I tried to build, download and run the program just to make sure everything still worked.

Sure enough, it doesn't. In Debug mode, I see the NIOS II processor seems to lock up the moment it gets to any IOWR routine to write to the PIO for the LEDs (again, there is no code referencing the other PIOs, beyond what is generated by the BSP).

What could be causing the CPU to lock up? The lack of an ISR for the interrupt I just created? I thought the interrupt was disabled until I registered it.

16 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    Are you passing in the base address of the PIO defined by system.h? If so I would look at the base address macro in system.h and compare it against what is shown in the Qsys UI to make sure they match.

    --- Quote End ---

    I have made sure that both the address specified in the Qsys and the system.h are same.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    Are you passing in the base address of the PIO defined by system.h? If so I would look at the base address macro in system.h and compare it against what is shown in the Qsys UI to make sure they match.

    --- Quote End ---

    I have made sure that both the address specified in the Qsys and the system.h are same.

    In my Qsys i have a 16 bit PIO which i configured it as bidirectional.Will it create any problem?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    No that shouldn't have caused a problem. When the PIO is bidirectional with a single tristate bus that connects off-chip there is a direction register that you write to in order to switch between input and output. If you have it set to input but attempt to write data I forget what the behavior is (probably stores the data but continues being an input) but I wouldn't expect that to cause a lockup. I recommend simulating the design, that's what I typically do when debugging system deadlocks. You'll want to look at the Nios II masters, the PIO slave port, and if you have any bridges between the CPU and PIO look at those in the simulation as well. This will let you determine where in the system the lockup occurs. Sometimes I also include the slave port of the memory I'm executing code out of as well. To track what the CPU is doing during the simulation I often look at the objdump file for the executable and correlate the addresses that the instruction master issues to the addresses in the objdump to figure out approximately which instructions are being executed.

    Also if you are using a small on-chip RAM to store your code, you might want to try temporarily increasing the size of the memory if you have room just in case you are running into a stack and heap collision.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    hai BadOmen,

    Can you tell me a little bit in detail of the bidirectional PIO's.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    You can find the PIO component documentation here: https://www.altera.com/content/dam/altera-www/global/en_us/pdfs/literature/ug/ug_embedded_ip.pdf

    The PIO supports a combined input/output mode in two ways. One mode has separate input and output ports so that when you write to the data register it is sent to the output and when you read from the data register the input is returned to the requesting master. The other mode uses bidirectional data which means that a single tri-state interface is exposed (Verilog it's inout, I forget what VHDL calls it) which means you have to write to the direction register to control whether that tri-state port drives out the data or if it reads data. Bidirectional ports can only drive a 0, drive a 1, or be an input so that's why you have to select it's direction by setting up the direction register.
  • oakbati's avatar
    oakbati
    Icon for New Contributor rankNew Contributor

    I was having the same problem and it had been working smoothly before... Then I found out the problem, we had been using a traditional way to create the eclipse project but we had changed it without knowing the consequences... Later we recognized that the problem is occurring based on that issue...
    Just watch the following video and create your eclipse project in the same way: https://youtu.be/yEtVLTB4hM4?si=C0HlQL3kbLcNkep5

    This should solve the problem.