cancel
Showing results for 
Search instead for 
Did you mean: 

UART4 MPU fault exception

feng_wang
Associate II
Posted on October 20, 2015 at 14:44

Hi,

I use the UART4 of stm32f103ZGH6 on my application board as a RS 232 port. When I load the main app program with Keil uVision4 into the target flash starting at 0x08000000, the RX/TX of UART4 work fine. However, if I load the app program into the flash starting at 0x08010000 because I want to reserve 64K starting at 0x08000000 for boot loader program, the TX of UART4 still works, but the RX causes the MemManager_Handler exception before calling the UART4_IRQHandler(). My boot loader program doesn't do anything except jump to the main app program right now. I have USART1 for another RS 232 port in this program, its RX/TX work at both starting address, 0x08000000 or 0x08010000. So my question is whether the UART4 needs some special settings or confirguration. The UART4 code I use is as below. The system is configured for PriorityGroup 4, so I set the interrupt priority of UART4 to 7 and its subpriority to 0.

Thank you for your ideas in advance.

RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);

USART_InitStructure.USART_BaudRate = 9600;

USART_InitStructure.USART_WordLength = USART_WordLength_8b;

USART_InitStructure.USART_StopBits = USART_StopBits_1;

USART_InitStructure.USART_Parity = USART_Parity_No;

USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

GPIO_Init(GPIOC, &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

GPIO_Init(GPIOC, &GPIO_InitStructure);

USART_Init(UART4, USART_InitStructure);

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 7;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn;

NVIC_Init(&NVIC_InitStructure);

USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);

USART_Cmd(UART4, ENABLE);

UART4_IRQHandler(void);

7 REPLIES 7
Posted on October 20, 2015 at 14:56

Did you redirect the interrupt vector table?

JW
Posted on October 20, 2015 at 15:31

Per Jan, SCB->VTOR = 0x08010000, check SystemInit() in system_stm32f1xx.c

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
feng_wang
Associate II
Posted on October 22, 2015 at 16:55

Thank you very much for your prompt. I do redirect the interrupt vector table,  SCB->VTOR = 0x08010000, in SystemInit() in system_stm32f1xx.c. The interesting is I define the USART1 also in my application for another RS port, the USART1 port doesn't have the MemManager_Handle exception issue when I load the app program to Flash starting at 0x08010000, but UART4 port has. May I miss some other settings?

Posted on October 22, 2015 at 21:30

Make sure the handler name exactly matches the name called out in the vector table (startup_stm32f1xx.s) and that the linker has bound the two, and the address for the UART4 entry in the table physically points at your code. Look at the .MAP, and the output in the .HEX/.BIN. If you have a disassembly, look at that.

Make sure you haven't mixed UART and USART in the naming.

Failing that zip up the whole project and output files, and attach.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
feng_wang
Associate II
Posted on November 19, 2015 at 23:21

Hi Clive,

I have confirmed the handler name in my app program and in the vector table (startup_stm32f10x_hd.s), and checked the Map file also. The naming seems correct. I just don't know how to bind two in the Linker of Keil uVision as you mentioned. In order to make this problem clear, I delete other functions from my app except USART1, UART4 and UART5 functions. I would summarize my test for your reference.

1. If I build a debug version or release version of my app program with the pointer to the vector table 0x08000000, USART1, UART4 and UART5 work correct.

2. If I implement a bootloader program first which just jumps to the app start address 0x08010100, and build the release version of my app with pointer to the vector 0x08010100, USART1 TX/RX, UART4 TX and UART5 TX work, but UART4 RX and UART5 RX will trigger the exception MemManage_Handler. I set a signal at beginning of UART4_IRQHandler, but the oscilloscope is not triggered, that means the exception occurs before executing the IRQHandler.By the way, the bootloader's pointer to vector table is 0x08000000.

I tried to attach the zip file of whole project for you several times, unfortunately it always showed error. Can you give me another way to email you the zip file? This zip file includes the settings of Keil uVision4. Please let me know whether you need my bootloader project and ST Peripheral Lib 3.4 I use also.

Thank you in advance.    

Posted on November 20, 2015 at 00:55

Click on my Avatar/Profile. A Google Drive share would work too.

I'm using v3.5.0, but likely have 3.4.0 if that's the issue. Just send the test app for now, and I'll see if I can figure out what's happening there first.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
feng_wang
Associate II
Posted on November 20, 2015 at 14:18

My system seems hard to let me access to a share drive.

My email is feng_wang@amat.com

Can you email me a message so that I can attach the zip file to email and back to you?

Thanks.