硬汉嵌入式论坛

 找回密码
 立即注册
查看: 1155|回复: 4
收起左侧

[脱机烧录] 添加Renesas(瑞萨)RA系列烧录,执行初始化失败。

[复制链接]

757

主题

1049

回帖

3325

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
3325
发表于 2022-4-8 09:18:51 | 显示全部楼层 |阅读模式
2022-04-08  这几天调试瑞萨 R7FA2L1A9 芯片, M23内核,128KB,遇到问题。

执行 FLM文件中的 int Init (unsigned long adr, unsigned long clk, unsigned long fnc) 函数,返回失败。
瑞萨开放了FLM源文件,增加调试语句,发现是它判断时钟不达标,必须在 1M - 48M之间。
大多数FLM文件都没有使用 clk形参,但是瑞莎的使用了。

于是在lua脚本中新增一个参数 FLM_INIT_CLK = 48 * 1000000。
还不确定这个是晶振频率,还是内部PLL倍频后的主频。

不过改了这个还没解决问题。跟踪发现init函数内部并未用到clk
[C] 纯文本查看 复制代码
// 增加调试语句
#define LogIdx *(DWORD *)(0x20002000)
#define TEST_LOG(x) {*(BYTE *)(0x20002000 + LogIdx) = x; LogIdx = LogIdx + 1;}

/*
 *  Initialize Flash Programming Functions
 *    Parameter:      adr:  Device Base Address
 *                    clk:  Clock Frequency (Hz)
 *                    fnc:  Function Code (1 - Erase, 2 - Program, 3 - Verify) - Ignored
 *    Return Value:   0 - OK,  1 - Failed
 */
int Init (unsigned long adr, unsigned long clk, unsigned long fnc)
{
	// Temporary variable to store mode & clock checking result
	BYTE byteClockCheckResult;
	BYTE byteUserClockValue;
	DWORD dwPEAddr;
	
    
    LogIdx = 4;
    
	dwICLKValue = 0;
	
	// Save current settings
	saveModeAndClock();
	
	// Check if flash is rewritable with current clock and power control mode
	byteClockCheckResult = checkModeAndClock(&clk);
	
    TEST_LOG(1);
    
	// If the flash is not rewritable with current settings, switch to a possible state
	#ifdef CHG_CLK_AND_MOD_ENA
		
	if(byteClockCheckResult == RES_ERROR)
	{
		// Change power mode and clock to state that allows rewrite flash
		byteClockCheckResult = changeModeAndClock(&clk);
  }
	#endif
  
TEST_LOG(2);
  
	// Return Failure if the flash cannot be rewritten and stop other processing
	if(byteClockCheckResult)
	{
TEST_LOG(3);
        
		return (RES_ERROR); // Finished with Errors
  }
    
TEST_LOG(4);
  
	// Save ICLK frequency for wait processing
	dwICLKValue = clk;
	// Convert clock from Hz to MHz unit
	byteUserClockValue = clk / 1000000;
	// Round up the first decimal place in MHz
	if (clk % 1000000)
	{
		byteUserClockValue += 1;
	}
	
	// Enter PE Mode
	enterPEMode(adr, &dwPEAddr);
	
	// Set Peripheral Clock Notification
	// Because (FlashIF Clock Frequency [MHz]) 1.0 = (PCKA [5:0] Bit Setting) 00000b
	// So we decrease clock value by 1 before convert to bit string.
	// Note: This register can be set only in PE Mode
	if(byteUserClockValue <= 32)
	{
		M8(MCU_FISR_ADDR) = (M8(MCU_FISR_ADDR) | (byteUserClockValue - 1));
	} else
	{
		M8(MCU_FISR_ADDR) = (M8(MCU_FISR_ADDR) | ((byteUserClockValue >> 1) + 15));
	}
	
	// Reset all Flash register to apply new FCLK
	M8(MCU_FRESETR_ADDR) = 1;
	M8(MCU_FRESETR_ADDR) = 0;
	
	// Go to READ Mode
	M16(MCU_FENTRYR_ADDR) = FENTRYR_READ_MODE;
	
TEST_LOG(5);
  return checkInternalError(); // Check internal errors
}

/*
 *  Check Mode & Clock for rewriting flash
 *    Parameter:      clk: Input clock value (Hz)
 *    Return Value:   0 - OK,  1 - Failed
 */
static BYTE checkModeAndClock(DWORD *clk)
{
	// Temporary variable to store user settings
	DWORD dwUserClockValue;
	WORD wUserClockDivisionIndex;
	WORD wUserClockDivisionValue;
	
    TEST_LOG(10);
    
	// Return Failure if Sub Operating Power Control Mode = Subosc-speed
	if ((userRegisterValue[SOPCCR] & SOPCCR_SOPCM_MASK) == SOPCCR_SOPCM_SUBMODE)
	{
        TEST_LOG(11);
		return (RES_ERROR); // Finished with Errors
	}
	
	// Check and Get current clock speed
	switch (userRegisterValue[SCKSCR] & SCKSCR_CKSEL_MASK)
	{
		case SCKSCR_CKSEL_MOSC:
			// Input clock source is External clock
			dwUserClockValue = *clk;
            TEST_LOG(0x30);
			break;
		case SCKSCR_CKSEL_HOCO:
			// Get settings frequency
			if ((userRegisterValue[OFS1] & OFS1_HOCOFRQ1_MASK) == OFS1_HOCOFRQ1_24MHZ)
			{
				dwUserClockValue = 24000000;
                TEST_LOG(0x31);
			} else if ((userRegisterValue[OFS1] & OFS1_HOCOFRQ1_MASK) == OFS1_HOCOFRQ1_32MHZ)
			{
				dwUserClockValue = 32000000;
                TEST_LOG(0x32);
			} else if ((userRegisterValue[OFS1] & OFS1_HOCOFRQ1_MASK) == OFS1_HOCOFRQ1_48MHZ)
			{
				dwUserClockValue = 48000000;
                TEST_LOG(0x33);
			} else if ((userRegisterValue[OFS1] & OFS1_HOCOFRQ1_MASK) == OFS1_HOCOFRQ1_64MHZ)
			{
				dwUserClockValue = 64000000;
                TEST_LOG(0x34);
			} else
			{
                TEST_LOG(12);
				// Invalid settings
				return (RES_ERROR); // Finished with Errors
			}
			break;
		case SCKSCR_CKSEL_MOCO:
			// MOCO frequency is fixed as 8MHz
			dwUserClockValue = 8000000;
        TEST_LOG(0x35);
			break;
		case SCKSCR_CKSEL_LOCO: // Flash is not rewriteable in LOCO (frequency < 4MHz)
		case SCKSCR_CKSEL_SOSC: // Flash is not rewriteable in SOSC (frequency < 4MHz)
		default:
            TEST_LOG(0x36);
			return (RES_ERROR); // Finished with Errors
	}
	// Calculate actual clock speed (by combining with Frequency Division)
	wUserClockDivisionIndex = (userRegisterValue[SCKDIVCR] & SCKDIVCR_ICK_MASK) >> 24;
	if (wUserClockDivisionIndex == SCKDIVCR_ICK_DIV_1)
	{
		wUserClockDivisionValue = 1;
        TEST_LOG(0x37);
	} else if (wUserClockDivisionIndex == SCKDIVCR_ICK_DIV_2)
	{
		wUserClockDivisionValue = 2;
        TEST_LOG(0x38);
	} else if (wUserClockDivisionIndex == SCKDIVCR_ICK_DIV_4)
	{
		wUserClockDivisionValue = 4;
        TEST_LOG(0x39);
	} else if (wUserClockDivisionIndex == SCKDIVCR_ICK_DIV_8)
	{
		wUserClockDivisionValue = 8;
        TEST_LOG(0x4A);
	} else if (wUserClockDivisionIndex == SCKDIVCR_ICK_DIV_16)
	{
		wUserClockDivisionValue = 16;
        TEST_LOG(0x4B);
	} else if (wUserClockDivisionIndex == SCKDIVCR_ICK_DIV_32)
	{
		wUserClockDivisionValue = 32;
        TEST_LOG(0x4C);
	} else if (wUserClockDivisionIndex == SCKDIVCR_ICK_DIV_64)
	{
		wUserClockDivisionValue = 64;
        TEST_LOG(0x4D);
	} else
	{
        TEST_LOG(13);
		// Invalid setting
		return (RES_ERROR); // Finished with Errors
	}
	*clk = dwUserClockValue / wUserClockDivisionValue;
	
	// Return Failure if current clock speed out of accepted range
	if (((*clk) < FLASH_WRITEABLE_MIN_CLOCK_HZ) || ((*clk) > FLASH_WRITEABLE_MAX_CLOCK_HZ))
	{
        M32(0x20002104) = *clk;
        TEST_LOG(14);
		return (RES_ERROR); // Finished with Errors
	}
	
	return (RES_OK); // Finished without Errors
}

回复

使用道具 举报

757

主题

1049

回帖

3325

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
3325
 楼主| 发表于 2022-4-8 11:55:01 | 显示全部楼层
问题已解决。修改原厂的FLM文件。

[C] 纯文本查看 复制代码
/*
 *  Change Mode & Clock for rewriting flash
 *    Parameter:      clk: Input clock value (Hz)
 *    Return Value:   0 - OK,  1 - Failed
 */
static BYTE changeModeAndClock(DWORD *clk)
{
        // Unprotect some registers
        M16(MCU_PRCR_ADDR) = PRCR_KEY | PRCR_PRC0_ENABLE | PRCR_PRC1_ENABLE;

        // If Sub Operating Power Control Mode = Subosc-speed, set to Other
        if ((M8(MCU_SOPCCR_ADDR) & SOPCCR_SOPCM_MASK) == SOPCCR_SOPCM_SUBMODE)
        {
                M8(MCU_SOPCCR_ADDR) = SOPCCR_SOPCM_OTHMODE;
        }
        // Wait until it successfully sets
        while ((M8(MCU_SOPCCR_ADDR) & SOPCCR_SOPCMTSF_MASK) != SOPCCR_SOPCMTSF_COMPL)
        {
                // Do nothing
                ;
        }
        
        // If OFS1 is in initial state, use MOCO
        if ((M32(MCU_OFS1_ADDR) & OFS1_HOCOFRQ1_MASK) == OFS1_HOCOFRQ1_MASK)
        {
        TEST_LOG(0x50);
                // Change clock source to MOCO
                if (M8(MCU_SCKSCR_ADDR) != SCKSCR_CKSEL_MOCO)
                {
                        // If MOCO is stoped, start it
                        if (M8(MCU_MOCOCR_ADDR) == MOCOCR_STOP)
                        {
                                M8(MCU_MOCOCR_ADDR) = MOCOCR_ON;
                                // Wait until MOCO is stable
                                Wait_us(15);
                                while ((M8(MCU_OSCSF_ADDR) & OSCSF_MOSCSF_MASK) != OSCSF_MOSCSF_STABLE)
                                {
                                        // Do nothing
                                        ;
                                }
                        }
                        // Select clock as MOCO
                        M8(MCU_SCKSCR_ADDR) = SCKSCR_CKSEL_MOCO;
                }
                // Frequency is 8MHz
                *clk = 8000000;
        } else
        { // Otherwise, use HOCO
        TEST_LOG(0x51);
                // Change clock source to HOCO
                if (M8(MCU_SCKSCR_ADDR) != SCKSCR_CKSEL_HOCO)
                {
                        // If HOCO is stoped, start it
                        if (M8(MCU_HOCOCR_ADDR) == HOCOCR_STOP)
                        {
                                M8(MCU_HOCOCR_ADDR) = HOCOCR_ON;
                                // Wait until HOCO is stable
                                while ((M8(MCU_OSCSF_ADDR) & OSCSF_HOCOSF_MASK) != OSCSF_HOCOSF_STABLE)
                                {
                                        // Do nothing
                                        ;
                                }
                        }
                        // Select clock as HOCO
                        M8(MCU_SCKSCR_ADDR) = SCKSCR_CKSEL_HOCO;
                }
                // Frequency is 24/32/48/64 MHz
        M32(0x20002200) = M32(MCU_OFS1_ADDR);
        
                switch (M32(MCU_OFS1_ADDR) & OFS1_HOCOFRQ1_MASK)
                {
                        case OFS1_HOCOFRQ1_24MHZ:
                                *clk = 24000000;
                TEST_LOG(0x52);
                                break;
                        case OFS1_HOCOFRQ1_32MHZ:
                                *clk = 32000000;
                TEST_LOG(0x53);
                                break;
                        case OFS1_HOCOFRQ1_48MHZ:
                                *clk = 48000000;TEST_LOG(0x54);
                                break;
                        case OFS1_HOCOFRQ1_64MHZ:
                                *clk = 64000000;
            TEST_LOG(0x55);
                                break;
                        default:
                TEST_LOG(0x56);
            break;  // 安富莱add
                                return (RES_ERROR); // Finished with Errors
                }
        }
        
        if (*clk != 64000000)
        {
        TEST_LOG(0x57);
        // Change clock division to 1
                M32(MCU_SCKDIVCR_ADDR) = SCKDIVCR_ICK_DIV1_MASK;
        } else
        {
        TEST_LOG(0x58);
                // Change clock division to 2
                M32(MCU_SCKDIVCR_ADDR) = SCKDIVCR_ICK_DIV2_MASK;
                *clk = 32000000;
        }
        
        return (RES_OK); // Finished without Errors
}


第89行,直接break,而不是return.下面是H7-TOOL烧录日志。 2.5秒烧录128KB。瑞萨的FLASH擦写速度还不错
[C] 纯文本查看 复制代码
开始烧录...
单路烧录
SWCLK时钟延迟:         0
core_id = 0x5BA02477
uid1 = 
------------------------
FLM : 0:/H7-TOOL/Programmer/Device/Renesas/FLM/RA2L1_128K.FLM
Data: 128K_5A.bin
Addr: 0x00000000, cfg = 1
FLM memory Infomation :
  algo file : 0:/H7-TOOL/Programmer/Device/Renesas/FLM/RA2L1_128K.FLM
  AlgoRamAddr = 0x20000000
  AlgoRamSize = 0x2000
  ----Device Info------------------------
  Version & Architecture : 0x0101
  Device Name : RA2L1 256KB Flash
  Device Type : 1
  Device Addr : 0x00000000
  Device Size : 256KB (0x40000)
  Page Size   : 128B
  Reserved    : 0x00000000
  Erased Content : 0xFF
  Program Page TimeOut   : 100
  Erase Sector TimeOut   : 3000
  Erase Sector Size      : 00000000, 2KB (0x800)
  ----Algo function offset ---------------
  Load Offset : 0x00000034
  Load Size   : 0x00001084
  FlashDevice : 0x000010B8
  Init        : 0x00000001
  UnInit      : 0x0000081D
  BlankCheck  : 0x00000EB5
  EraseChip   : 0x000008CD
  EraseSector : 0x000009C9
  ProgramPage : 0x00000AE9
  Verify      : 0x00000DC9
  CaculCRC32  : 0x00000000
  GetSN       : 0x00000000
  ----Algo RAM Info---------------------------
  algo ram address   : 0x20000000
  algo size          : 0x000010A4
  buffer address     : 0x200010A4
  buffer size        : 0x00000080
  breakpoint addres  : 0x20000001
  static base adress : 0x20001124
  stack pointer      : 0x20002000
  Init        : 0x20000021
  UnInit      : 0x2000083D
  BlankCheck  : 0x20000ED5
  EraseChip   : 0x200008ED
  EraseSector : 0x200009E9
  ProgramPage : 0x20000B09
  Verify      : 0x20000DE9
InitUnderReset()
OK
.NVIC_CPUID = 411CD200, Cortex-M23
正在检查空片 
  74ms, 0.00%
  76ms, 100.00%
正在擦除整片...
  78ms, 0.00%
  81ms, 0.00%
  103ms, 100.00%
正在编程...
  104ms, 0.00%
.......
  2207ms, 100.00%
正在校验...(Readback)
  2255ms, 0.00%
.......
  2500ms, 100.00%
编程成功






回复

使用道具 举报

757

主题

1049

回帖

3325

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
3325
 楼主| 发表于 2022-4-8 23:12:20 | 显示全部楼层
突然板子不能用了。可以识别到IDCODE。无法连接IC。
J-Link也不行。难道CPU坏了?
随便烧录一个文件导致的,之前好好的可反复下载。

难不成被保护了。
回复

使用道具 举报

757

主题

1049

回帖

3325

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
3325
 楼主| 发表于 2022-4-9 01:10:03 | 显示全部楼层
用瑞萨的flasher 软件,jlink作为连接


image.png
https://www.renesas.com/rfp-error-guide#no-response
回复

使用道具 举报

757

主题

1049

回帖

3325

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
3325
 楼主| 发表于 2022-4-9 01:16:58 | 显示全部楼层

image.png
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-11-1 07:35 , Processed in 0.275098 second(s), 27 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表