I Run the sample code of USB_CDC_VCOM_BM. In IAR Showing Hard fault Handle error and Accessing Illegal memory address, When Debugging the code. Kindly If anyone find the solution let me know
/*! @brief FROHF clock setting API address in ROM. */
#define CLOCK_FROHF_SETTING_API_ROM_ADDRESS (0x030091DFU)
/*showing Hard fault error when reach this function*/
#define set_fro_frequency(iFreq) (*((void (*)(uint32_t iFreq))(CLOCK_FROHF_SETTING_API_ROM_ADDRESS)))(iFreq)
i'm not sure, why its showing error, SO I attached Example code
##SDK version - 2.13.0
Using ##Lpc54606j256 microcontroller, IAR TOO
Hi,
Regarding your question of hard-fault error when the code is executed.
Pls check the following items:
1)disable interrupt before you call the api function, after calling, enable interrupt.
__STATIC_FORCEINLINE void __enable_irq(void)
{
__ASM volatile ("cpsie i" : : : "memory");
}
__disable_irq();
set_fro_frequency(96000000);
__enable_irq();
2)enable ROM bit in SYSCON->AHBCLKCTRL0|=1<<1; in this way, you can call the ROM code
3)Because set_fro_frequency(96000000); function configure the FRO to output 96MHz clock, it is unnecessary to configure the SYSCON->FROCTROL in application code.
Pls have a try
BR
XiangJun Rong
Hi,
Pls try to use the SDK example to set the 96MHz clock as main clock
void BOARD_BootClockFROHF96M(void)
{
/*!< Set up the clock sources */
/*!< Set up FRO */
POWER_DisablePD(kPDRUNCFG_PD_FRO_EN); /*!< Ensure FRO is on */
CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch to FRO 12MHz first to ensure we can change voltage without accidentally
being below the voltage for current speed */
POWER_SetVoltageForFreq(96000000U); /*!< Set voltage for the one of the fastest clock outputs: System clock output */
CLOCK_SetFLASHAccessCyclesForFreq(96000000U); /*!< Set FLASH wait states for core */
/*!< Need to make sure ROM and OTP has power(PDRUNCFG0[17,29]= 0U)
before calling this API since this API is implemented in ROM code */
CLOCK_SetupFROClocking(96000000U); /*!< Set up high frequency FRO output to selected frequency */
/*!< Set up dividers */
CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false); /*!< Reset divider counter and set divider to value 1 */
/*!< Set up clock selectors - Attach clocks to the peripheries */
CLOCK_AttachClk(kFRO_HF_to_MAIN_CLK); /*!< Switch MAIN_CLK to FRO_HF */
/* Set SystemCoreClock variable. */
SystemCoreClock = BOARD_BOOTCLOCKFROHF96M_CORE_CLOCK;
}
Pls have a try
BR
XiangJun Rong
Hi,
I have checked your example, it is based on IAR tools, but my IAR tools license has expired.
I have called the BOARD_BootClockFROHF96M() api function and run it on my LPC54628-EVK board, no problem.
BR
XiangJun Rong
void BOARD_BootClockFROHF96M(void)
{
/*!< Set up the clock sources */
/*!< Set up FRO */
POWER_DisablePD(kPDRUNCFG_PD_FRO_EN); /*!< Ensure FRO is on */
CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch to FRO 12MHz first to ensure we can change voltage without accidentally
being below the voltage for current speed */
POWER_SetVoltageForFreq(96000000U); /*!< Set voltage for the one of the fastest clock outputs: System clock output */
CLOCK_SetFLASHAccessCyclesForFreq(96000000U); /*!< Set FLASH wait states for core */
/*!< Need to make sure ROM and OTP has power(PDRUNCFG0[17,29]= 0U)
before calling this API since this API is implemented in ROM code */
CLOCK_SetupFROClocking(96000000U); /*!< Set up high frequency FRO output to selected frequency */
/*!< Set up dividers */
CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false); /*!< Reset divider counter and set divider to value 1 */
/*!< Set up clock selectors - Attach clocks to the peripheries */
CLOCK_AttachClk(kFRO_HF_to_MAIN_CLK); /*!< Switch MAIN_CLK to FRO_HF */
/* Set SystemCoreClock variable. */
SystemCoreClock = BOARD_BOOTCLOCKFROHF96M_CORE_CLOCK;
}
Hi,
I have called the BOARD_BootClockFROHF96M() api function and run it on my LPC54606j256 Microcontroller, but I have problem in this function. Let me know if any other way to find this issue. Past 2weeks working on this still now I didn't solve this issue. So, I need help for this. Please if you have any suggestions tell me and what should i do next?
I'm using IAR Embedded workbench IDE - Arm 9.32.2 tool and SDK version - 2.13.0
Example - dev_cdc_vcom_bm for USB
I'm also using same BOARD_BootClockFROHF96M(void) function same code, but I don't know, why its not working?
can you tell? should I change tool or SDK version (or) anything changes in my code?
void BOARD_BootClockFROHF96M(void)
{
/*! < Set up the clock sources */
/*! < Set up FRO */
POWER_DisablePD(kPDRUNCFG_PD_FRO_EN); /*!< Ensure FRO is on */
CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch to FRO 12MHz first to ensure we can change voltage without
accidentally being below the voltage for current speed */
POWER_SetVoltageForFreq(96000000U); /*!< Set voltage for the one of the fastest clock outputs: System clock output */
CLOCK_SetFLASHAccessCyclesForFreq(96000000U); /*!< Set FLASH wait states for core */
/*! < Need to make sure ROM and OTP has power(PDRUNCFG0[17,29]= 0U)
before calling this API since this API is implemented in ROM code */
CLOCK_SetupFROClocking(96000000U); /*!< Set up high frequency FRO output to selected frequency */
/*! < Set up dividers */
CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false); /*! < Reset divider counter and set divider to value 1 */
/*! < Set up clock selectors - Attach clocks to the peripheries */
CLOCK_AttachClk(kFRO_HF_to_MAIN_CLK); /*! < Switch MAIN_CLK to FRO_HF */
/* Set SystemCoreClock variable. */
SystemCoreClock = BOARD_BOOTCLOCKFROHF96M_CORE_CLOCK;
}
Hi,
Pls check if the PDRUNCFG0[17,29]= 0U, which power up the ROM.
Pls refer to section 7.5.84 Power Configuration register 0 in UM10912.pdf
/*!< Need to make sure ROM and OTP has power(PDRUNCFG0[17,29]= 0U)
before calling this API since this API is implemented in ROM code */
CLOCK_SetupFROClocking(96000000U); /*!< Set up high frequency FRO output to selected frequency */
BR
XiangJun Rong
Hi XiangJun Rong,
I think problem in ROM Address because Showing error "Memory access error".
/*! @brief FROHF clock setting API address in ROM. */
#define CLOCK_FROHF_SETTING_API_ROM_ADDRESS (0x030091DFU)
/*showing Hard fault error when reach this function*/
#define set_fro_frequency(iFreq) (*((void (*)(uint32_t iFreq))(CLOCK_FROHF_SETTING_API_ROM_ADDRESS)))(iFreq)
Hi,
If you suspect that the ROM address is incorrect, pls try to execute IAP instruction for example reading part identification number, for detailed inf, pls refer to section 5.6.5 Read part identification number in UM10912.pdf
Hope it can help you
BR
XiangJun Rong
Hi,
I attached terminal output image for your reference. If I enter something in USB terminal, didn't reflecting in UART terminal because some macros and functions are not defined. so, it's not entering in the functions, I mentioned below and mark in red colour. you can refer the readme pdf for your reference.
#if defined(FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED) && (FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED > 0U) && \
defined(USB_DEVICE_CONFIG_KEEP_ALIVE_MODE) && (USB_DEVICE_CONFIG_KEEP_ALIVE_MODE > 0U) && \
defined(FSL_FEATURE_USB_KHCI_USB_RAM) && (FSL_FEATURE_USB_KHCI_USB_RAM > 0U)
if ((s_waitForDataReceive))
{
if (s_comOpen == 1)
{
/* Wait for all the packets been sent during opening the com port. Otherwise these packets may
* wake up the system.
*/
usb_echo("Waiting to enter lowpower ...\r\n");
for (uint32_t i = 0U; i < 16000000U; ++i)
{
__NOP(); /* delay */
}
s_comOpen = 0;
}
usb_echo("Enter lowpower\r\n");
BOARD_DbgConsole_Deinit();
USB0->INTEN &= ~USB_INTEN_TOKDNEEN_MASK;
USB_EnterLowpowerMode();
s_waitForDataReceive = 0;
USB0->INTEN |= USB_INTEN_TOKDNEEN_MASK;
BOARD_DbgConsole_Init();
usb_echo("Exit lowpower\r\n");
}
#endif
}
Hi,
Now it's working in MCUXpresso IDE, but I don't know why it's not working in IAR. I have problem in MCUXpresso IDE, that problem is some macro definitions and functions are not defined in the code. so, I need your help.
macros:
FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED
FSL_FEATURE_USB_KHCI_USB_RAM
USB_INTEN_TOKDNEEN_MASK and USB_INTEN_SOFTOKEN_MASK
Functions:
void BOARD_InitHardware(void);
void BOARD_DbgConsole_Deinit(void);
void BOARD_DbgConsole_Init(void);
extern uint8_t USB_EnterLowpowerMode(void);
In USB terminal (Tera term) we enter something, it's reflected in UART terminal like printing msg. when we are debugging the code.
We enter something in USB terminal, how do we know USB port data transfer send correctly or not?
I attached code for your reference, can you check and update me.
Hi,
I suggest you download SDK package based on Windows and MCUXPresso tools.
https://mcuxpresso.nxp.com/en/select
BR
XiangJun Rong