Reputation: 809
I run USB virtual com port example on NXP LPC1768 successfully, in Keil environment.
by default, the code is in privileged mode.
for example, I added a single line for accessing PWM peripheral and it causes HardFault error.
Also, I tried
__SVC
solution but it causes HardFault too.
this is Keil pack installer example and I only added a header and a line about PWM:
#include "cmsis_os.h"
#include "rl_usb.h"
#include "Board_GLCD.h"
#include "GLCD_Config.h"
#include "LPC17xx.h" // Device header
extern GLCD_FONT GLCD_Font_6x8;
extern GLCD_FONT GLCD_Font_16x24;
int main (void) {
GLCD_Initialize ();
GLCD_SetBackgroundColor (GLCD_COLOR_BLUE);
GLCD_SetForegroundColor (GLCD_COLOR_WHITE);
GLCD_ClearScreen ();
GLCD_SetFont (&GLCD_Font_16x24);
GLCD_DrawString (0U, 0U*24U, " USB Device ");
GLCD_DrawString (0U, 1U*24U, " CDC ACM Class ");
GLCD_DrawString (0U, 2U*24U, " VirtualCOM Example ");
GLCD_DrawString (0U, 4U*24U, " USB <-> UART1 ");
GLCD_DrawString (0U, 8U*24U, " Keil Tools by ARM ");
GLCD_DrawString (0U, 9U*24U, " www.keil.com ");
USBD_Initialize (0U); // USB Device 0 Initialization
USBD_Connect (0U); // USB Device 0 Connect
LPC_PWM1->PR = 24; //PWM causes **hardFault**
while (1) {
osSignalWait (0U, osWaitForever);
}
}
Upvotes: 0
Views: 306
Reputation: 809
This causes by PC USB recognition problem.
It should solve by trying to off the device for 1 or 2 seconds, and then plug it in again.
Upvotes: 0
Reputation: 7701
LPC_PWM1 may not be enabled in the LPC_SC->PCONP
register. See chapter 4.8.9 in UM10360.pdf (reference manual).
Trying to access a disabled peripherial will cause a fault.
Upvotes: 1