• AVR Freaks

Hot!PIC32MX - Application UART interrupt not working when jumped to from Bootloader

Author
sjenkins2
New Member
  • Total Posts : 3
  • Reward points : 0
  • Joined: 2021/01/21 03:35:04
  • Location: 0
  • Status: offline
2021/01/22 04:06:19 (permalink)
0

PIC32MX - Application UART interrupt not working when jumped to from Bootloader

Hi,
 
I have created a bootloader for the PIC32MX270F512L on our custom board. This was based off the SD Card bootloader example and adapted to update the program flash with a binary image stored in external flash. The bootloader checks for a separate register stored in the external flash (which is updated by the app) to determine if program flash update should commence and the address where the binary image is stored. If this register does not exist, it will jump to the application if present, otherwise program the factory image which is always stored at a known address.  
 
I believe I have been able to successfully erase/program the application using the bootloader but the UART interrupt does not seem to be working. I have tried 'loading' the application with the bootloader so I could debug them both, and after jumping to the application code, was able to step through to the main while loop that just looks for incoming UART data from the PC terminal. The application works fine when programmed on its own without the linker file.
 
My first thought was that it has something to do with the IVT not being properly addressed and there is an issue with my linker file. However, I created a basic timer interrupt driven LED blink app and programmed that using the bootloader which seems works fine so its not all interrupts that are the problem...I then added UART to the test app but this failed to work. Again, if programmed on its own, it works fine!
 
I have made sure my config registers are the same between bootloader and application and also disable all interrupts before jumping to the application (using __builtin_disable_interrupts()).
 
I have the linker files setup so that the bootloader IVT is at the start of program flash (0x9D000000) and 12KB is allocated for my bootloader code just after. The application IVT and startup code base address is adjacent to this with the rest of the flash left for the application code. This is my first time doing a bootloader and found the process of updating the linker files not so straight forward so there could well be some issues there. I have attached them for comment.
 
Also my bootloader reset address is set as follows:
#define PROGRAM_FLASH_END_ADRESS (0x9D000000+BMXPFMSZ-1)

//-------User configurable macros begin---------
#define MAJOR_VERSION 1
#define MINOR_VERSION 0


/* APP_FLASH_BASE_ADDRESS and APP_FLASH_END_ADDRESS reserves program Flash for the application*/
/* Rule:
   1)The memory regions kseg0_program_mem, kseg0_boot_mem, exception_mem and
   kseg1_boot_mem of the application linker script must fall with in APP_FLASH_BASE_ADDRESS
   and APP_FLASH_END_ADDRESS
    
   2)The base address and end address must align on 4K address boundary */
   
#define APP_FLASH_BASE_ADDRESS 0x9D005000
#define APP_FLASH_END_ADDRESS PROGRAM_FLASH_END_ADRESS
#define APP_PROG_MEM_OFFSET 0x5000

/* Address of the Flash from where the application starts executing */
/* Rule: Set APP_FLASH_BASE_ADDRESS to _RESET_ADDR value of application linker script*/

// For PIC32MX1xx and PIC32MX2xx Controllers only
#define USER_APP_RESET_ADDRESS (0x9D004000 + 0x1000)

#define DEV_CONFIG_REG_BASE_ADDRESS 0x9FC00BF0
#define DEV_CONFIG_REG_END_ADDRESS 0x9FC00BFF

 
I feel like there may be something very simple I am overlooking here. Is anyone able to shed some light on this?
 
Thanks.
#1

7 Replies Related Threads

    cirilo.b
    Junior Member
    • Total Posts : 59
    • Reward points : 0
    • Joined: 2020/09/08 18:40:42
    • Location: 0
    • Status: offline
    Re: PIC32MX - Application UART interrupt not working when jumped to from Bootloader 2021/01/22 14:57:06 (permalink)
    0
    I don't see anything obviously wrong with your linker scripts.  For the app you assigned a cacheable address to kseg1_program, but I don't think that should matter as long as (a) the bootloader has initialized the cache controller and (b) the application's crt0.S code behaves correctly when run from a cacheable address.
     
    Check your vector address calculation scheme - if it's a fixed spacing calculation then make sure you have enough space reserved for the vector table (8K might do if 4K is too small). 
    #2
    sjenkins2
    New Member
    • Total Posts : 3
    • Reward points : 0
    • Joined: 2021/01/21 03:35:04
    • Location: 0
    • Status: offline
    Re: PIC32MX - Application UART interrupt not working when jumped to from Bootloader 2021/01/25 04:54:43 (permalink)
    0
    I've looked at the vector address calculation and that seems to only be 2K in size so it should be right set at a 4K boundary.
     
    Did you mean kseg0_program? I don't believe I have anything assigned to kseg1_program.
    How do you initialize the cache controller? Is there an easy way of checking the applications crt0.S code when debugging?
     
    Thanks for your help.
    #3
    Mysil
    Super Member
    • Total Posts : 4111
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: PIC32MX - Application UART interrupt not working when jumped to from Bootloader 2021/01/25 10:21:00 (permalink)
    0
    Hi,
    Source code for crt0.S
    is available in one of the directories of the compiler installation.
    It may be copied to source directory of your project, and inserted in bootloader and/or application project.
    There is some advice in comments in the file.
    Then you may follow it's operation in debugger.
     
        Mysil
    #4
    cirilo.b
    Junior Member
    • Total Posts : 59
    • Reward points : 0
    • Joined: 2020/09/08 18:40:42
    • Location: 0
    • Status: offline
    Re: PIC32MX - Application UART interrupt not working when jumped to from Bootloader 2021/01/25 13:16:30 (permalink)
    0
    Sorry, for the cacheable/non-cacheable, I meant your kseg1_boot_mem, not kseg1_program_mem. If you're using the default crt0.S it should initialize the cache, but I think it's good to look at that code anyway. When you look at the crt0.S you'll also see how the interrupt controller is set up and you can calculate the vector address of the UART interrupt that you're using.
     
    If you instruct the linker to generate the map file you can also look through that to see that your UART interrupt handler is there and that the vectored interrupt does execute that code.
     
    One other question is, what's your declaration for the UART interrupt handler?  Strange things can happen if the declaration is not correct.
    #5
    aschen0866
    Super Member
    • Total Posts : 4593
    • Reward points : 0
    • Joined: 2006/01/08 22:18:32
    • Location: San Diego
    • Status: offline
    Re: PIC32MX - Application UART interrupt not working when jumped to from Bootloader 2021/01/25 20:08:51 (permalink)
    0
    sjenkins2
    I have made sure my config registers are the same between bootloader and application and also disable all interrupts before jumping to the application (using __builtin_disable_interrupts()).

    Make sure you clear all IECx and IFSx registers before the jump. If DMA is used, you'll need to kill that too.
    #6
    sjenkins2
    New Member
    • Total Posts : 3
    • Reward points : 0
    • Joined: 2021/01/21 03:35:04
    • Location: 0
    • Status: offline
    Re: PIC32MX - Application UART interrupt not working when jumped to from Bootloader 2021/01/27 08:13:17 (permalink)
    4 (1)
    I have managed to find the problem after having tried looking into the things you all suggested.
     
    I setup the UART1 in my bootloader code, setting up the PPS, interrupts etc. and this allowed for the application UART to start working!
     
    I was then able to narrow it down to the app not being able to configure the PPS.
     
    In the datasheet:

    11.3.6.2 Configuration Bit Select Lock 
    As an additional level of safety, the device can be configured to prevent more than one write session to the RPnR and [pin name]R registers. The IOL1WAY Configuration bit (DEVCFG3<29>) blocks the IOLOCK bit from being cleared after it has been set once. If IOLOCK remains set, the register unlock procedure does not execute, and the peripheral pin select control registers cannot be written to. The only way to clear the bit and re-enable peripheral remapping is to perform a device Reset. In the default (unprogrammed) state, IOL1WAY is set, restricting users to one write session.
    After changing the UIL1WAY CONFIG to OFF, the UART pins are being setup correctly and behaving as normal.
     
    Thank you all for your help.
    #7
    cirilo.b
    Junior Member
    • Total Posts : 59
    • Reward points : 0
    • Joined: 2020/09/08 18:40:42
    • Location: 0
    • Status: offline
    Re: PIC32MX - Application UART interrupt not working when jumped to from Bootloader 2021/01/27 13:02:39 (permalink)
    0
    I typically operate with the 1-way lock bits (IO, PG, etc) being set but the lock bits are never programmed by the bootloader - after all a bootloader might support multiple products using the same controller board. It is the application that should provide the final configuration for the peripherals and lock the config bits if necessary. Doing it that way allows you to lock the bits but allows you to update to firmware which configures things differently - a useful feature if you find out later that you got some of the locked configuration bits wrong.
    #8
    Jump to:
    © 2021 APG vNext Commercial Version 4.5