- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi there all!
I've been trying to debug this code for a couple of days now but I'm still stuck. I've been looking for similar threads here and read most if it. I've also read "User guide embedded peripherals" and the "Software developer's handbook". The program is running without uCos and on an FPGA configuration with a UART configured as IRQ-level 1. When running the code below: I only get "1" in a Terminal software. The program crashes after the serial_init() call if I have the second printf("2"). If I remove printf("2"), the software proceeds to the while(1) loop since I can see my led is flashing. Any help is very welcome.
# include <stdio.h>
# include "system.h"
# include "altera_avalon_pio_regs.h"
# include "sys/alt_irq.h"
# include "alt_types.h"
# include "altera_avalon_uart_regs.h"
# include "altera_avalon_uart.h"
void serial_irq_0(void*, alt_u32);
void serial_init(unsigned int);
void serial_init(unsigned int baud)
{
unsigned int i;
/* inhibit all IRQ sources */
IOWR(UART_BASE, 3, 0x00);
/* set Baud rate */
IOWR(UART_BASE, 4, baud);
/* flush any characters sitting in the holding register */
i = IORD(UART_BASE, 0);
i = IORD(UART_BASE, 0);
/* reset most of the status register bits */
IOWR(UART_BASE, 2, 0x00);
/* install IRQ service routine */
alt_irq_register(UART_IRQ, 0, serial_irq_0);
/* enable irq for Rx. */
IOWR(UART_BASE, 3, 0x0080);
}
static void serial_irq_0(void* context, alt_u32 id)
{
unsigned int stat, chr, temp, counter, counter_max;
counter_max = 50000;
/* get serial status */
stat = IORD(UART_BASE, 2);
/* character Rx */
if (stat & 0x0080) {
chr = IORD(UART_BASE, 0);
}
// Clear the status register
IOWR(UART_BASE,2,0x0000);
}
int main()
{
int counter_max = 50000;
int counter = 0;
printf("1");
serial_init(115200);
printf("2");
while(1){
counter=0;
while(counter<counter_max){
counter++;
IOWR_ALTERA_AVALON_PIO_DATA(LED_BASE, 0x1);
}
counter=0;
while(counter<counter_max){
counter++;
IOWR_ALTERA_AVALON_PIO_DATA(LED_BASE, 0x0);
}
}
}
Regards, mr_embedded
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
not carefully read your code. you can put it within [ code] [ /code] Do "printf()" use your UART ? In another words, Do you read "1" on your UART or on your JTAG ? Are you sure your program crashes after serial_init(115200);. Maybe it crashes in serial_init(115200);.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
TO_BE_DONE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Unless you've disabled the HAL's UART driver, you're likely conflicting with it. Take a look at what's being initialized in alt_sys_init() (in alt_sys_init.c) and you should see what's being initialized and how.
Cheers, slacker- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks a lot Slacker!
This is what I found:
void alt_sys_init( void )
{
ALTERA_AVALON_JTAG_UART_INIT( JTAG_UART, jtag_uart );
ALTERA_AVALON_UART_INIT( UART, uart );
ALTERA_AVALON_CFI_FLASH_INIT( CFI_FLASH, cfi_flash );
}
So ALTERA_AVALON_UART_INIT( UART, uart ); is being called, I guess the function is defined in: "altera_avalon_uart.h" or am I completely wrong? I did a quick search on my harddrive for altera_avalon_uart.h and this file is located in Quartus and not the Nios directory. Do the functions get its parameters from the system.h ? Anyhow the questions above are quite unimportant. If I get it right, should I now try to locate the altera_avalon_uart.h and change the HAL-interrupt that I previously was interrupting with? My goal is to have a program that gets information through UART on interrupt and stores the data from the UART in a vector. Hope im not too confusing ;) Over and out, mr_embedded
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I looked over the altera_avalon_uart.h but couldn't find any information about the ISR that is being invoked when the UART is receiving data. Any idea where I can find this ISR instead of trying to write my own?
Always with regards, mr_embedded- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Actually, to start with, I would just comment out the UART_INIT function in alt_sys_init(). As to how the driver is actually structured, it uses a fair bit of C preprocessor macro "magic"...you can trace through it later....for now, it's better just to disable the UART init function and implement your custom one.
Using the UART for both your special communications needs and stdout is probably not a good idea. I would also switch stdout/stdin/stderr to jtag_uart. From there, you can tinker with various settings until you're happy. You could even write a new UART driver with prioritization for your communication needs. Cheers, slacker- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Slacker,
Thanks a lot. It will probably take a while but I will go for your way of doing it. For the stdout/stdin/stderr its quite handy to have them configured as JTAG as well. Once again, thanks! // mr_embedded
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page