seaman117 发表于 2011-11-10 18:08:02

关于在LPC1752移植碰到的相关问题,总是死在rt_hw_hard_fault_exception,请教ffxz和aoz

硬件:LPC1752(zlg开发板) + CF卡 (多余的IO脚已经悬空)
软件:RTT0.4.0RC
问题:跟踪发现每次都在rt_device_init_all中初始化串口1或者串口2或者串口3的Fdiv = ( pclk / 16 ) / UART0_BAUDRATE;处直接跳入fault_rvds的rt_hw_hard_fault    PROC再跳入硬件异常函数。初始化函数没有问题已经脱离RTT在工程中用过,软件仿真的时候能正常通过rt_device_init_all,怀疑是和硬件那里冲突,一时找不到!下面是初始化函数和异常响应的。finsh在串口0,去掉所有串口驱动则不会进入硬件异常。

static rt_err_t rt_uart_init (rt_device_t dev)
{
        rt_uint32_t Fdiv;
        rt_uint32_t pclkdiv, pclk;

        /* Init UART Hardware */
        LPC_PINCON->PINSEL0 &= ~0x000000F0;
        LPC_PINCON->PINSEL0 |= 0x00000050;/* RxD0 is P0.3 and TxD0 is P0.2 */
        /* By default, the PCLKSELx value is zero, thus, the PCLK for
        all the peripherals is 1/4 of the SystemFrequency. */
        /* Bit 6~7 is for UART0 */
        pclkdiv = (LPC_SC->PCLKSEL0 >> 6) & 0x03;
        switch ( pclkdiv )
        {
          case 0x00:
          default:
                pclk = SystemCoreClock/4;
                break;
          case 0x01:
                pclk = SystemCoreClock;
                break;
          case 0x02:
                pclk = SystemCoreClock/2;
                break;
          case 0x03:
                pclk = SystemCoreClock/8;
                break;
        }

    LPC_UART0->LCR = 0x83;                /* 8 bits, no Parity, 1 Stop bit */
        Fdiv = ( pclk / 16 ) / UART0_BAUDRATE;        /*baud rate */
    LPC_UART0->DLM = Fdiv / 256;          <==================== 此行跳入硬件异常,屏蔽后下面一行也进入到异常                               
    LPC_UART0->DLL = Fdiv % 256;
        LPC_UART0->LCR = 0x03;                /* DLAB = 0 */
    LPC_UART0->FCR = 0x07;                /* Enable and reset TX and RX FIFO. */

        /* Ensure a clean start, no data in either TX or RX FIFO. */
        while (( LPC_UART0->LSR & (LSR_THRE|LSR_TEMT)) != (LSR_THRE|LSR_TEMT) );
        while ( LPC_UART0->LSR & LSR_RDR )
        {
                Fdiv = LPC_UART0->RBR;        /* Dump data from RX FIFO */
        }
        LPC_UART0->IER = IER_RBR | IER_THRE | IER_RLS;        /* Enable UART interrupt */

        return RT_EOK;
}

psr: 0x00000000
pc: 0x00000000
lr: 0x00000000
r12: 0x00000000
r03: 0x00000000
r02: 0x00000000
r01: 0x00000000
r00: 0x00000000
hard fault on thread: (NULL)
threadpristatus      sp   stack size max used   left tickerror
-------- ---- ------- ---------- ---------- ---------- ---------- ---

seaman117 发表于 2011-11-10 18:16:16

static rt_size_t rt_ide_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size)
还有一个问题,CF卡驱动移植到RTT时,手册中也没有几个参数的含义?
size是指定扇区的地址还是要读取的个数?
pos是偏移量的位置还是偏移量?

已经实现了指定扇区地址上读写512B的底层函数
unsigned char WriteCompactFlashSector(unsigned long addr , unsigned char *buf)
unsigned char ReadCompactFlashSector(unsigned long addr , unsigned char *buf)

移植到rt_ide_read中是不是这样写

static rt_size_t rt_ide_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size)
{
        unsigned long count , offset , idx ;
        unsigned char *pData ;

        pData = ( unsigned char *)buffer ;

        count= size / 512 ;
        offset = (pos / 512) + part.offset ;

        for(idx = 0 ; idx < count ; idx++)
        {
                ReadCompactFlashSector(size , pData) ;
        }
        ReadCompactFlashSector(offset , pData) ;
       
        return count ;
}

zxq6 发表于 2011-11-10 19:25:44

楼主,这种涉及硬件的问题还是自己找原因来得快,我上次用RTT读写SDRAM也是碰到硬件问题,后来也只能自个解决。

seaman117 发表于 2011-11-10 20:19:23

是的,但是该找的都找了,现在没有思路了!

aozima 发表于 2011-11-10 20:38:48

Q:size是指定扇区的地址还是要读取的个数?
A:size直译为尺寸,肯定是指要读取的个数。以前单位是byte,为支持更大的设备,现在的单位是sector.

Q:pos是偏移量的位置还是偏移量?
A:rt_off_t pos, 即offset,单位也由原来的byte改为sector.

因此,驱动的 control 函数必须支持 RT_DEVICE_CTRL_BLK_GETGEOME 命令。
static rt_err_t rt_cf_control(rt_device_t dev, rt_uint8_t cmd, void *args)
{
    RT_ASSERT(dev != RT_NULL);

    if (cmd == RT_DEVICE_CTRL_BLK_GETGEOME)
    {
      struct rt_device_blk_geometry *geometry;

      geometry = (struct rt_device_blk_geometry *)args;
      if (geometry == RT_NULL) return -RT_ERROR;

      geometry->bytes_per_sector = 512; /* 非512字节每扇区的设备需要根据实际情况确定 */
      geometry->block_size = block_size;
      geometry->sector_count = 500G / geometry->bytes_per_sector;
    }

    return RT_EOK;
}

关于 hard_fault,先检查一下 board.h中SRAM的大小有没不对应,然后不要仿真,直接下载让其冷脱机跑一下是否正常。
如果正常,且是用JLINK仿真器,试下MDK示例中那个deg.ini,让在断点时关掉timer。
如还不行,那就不知道了。

seaman117 发表于 2011-11-10 20:51:24

aozima读写函数是否有问题呢??在使用DFS文件系统时,CF卡的驱动需要实现控制函数吗


static rt_size_t rt_ide_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size)
{
    unsigned long count , offset , idx ;
    unsigned char *pData ;

    pData = ( unsigned char *)buffer ;

    count= size / 512 ;
    offset = (pos / 512) + part.offset ;

    for(idx = 0 ; idx < count ; idx++)
    {
      ReadCompactFlashSector(size , pData) ;
    }
   
    ReadCompactFlashSector(offset , pData) ;

    return count ;
}


ReadCompactFlashSector是在指定的地址读一个扇区512Byte

seaman117 发表于 2011-11-10 21:23:49

ram我已经改了,因为是用的1752 Ram是8K,所以堆的定义应改到10004000,但是这样还是不行,同样的硬件异常@

#ifdef RT_USING_HEAP
        #ifdef __CC_ARM
                rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)0x10004000);
        #elif __ICCARM__
          rt_system_heap_init(__segment_end("HEAP"), (void*)0x10004000);
        #else
                /* init memory system */
                rt_system_heap_init((void*)&__bss_end, (void*)0x10004000);
        #endif
#endif

seaman117 发表于 2011-11-10 21:29:53

另外软件仿真没有出现问题,奇怪了!
页: [1]
查看完整版本: 关于在LPC1752移植碰到的相关问题,总是死在rt_hw_hard_fault_exception,请教ffxz和aoz