How to program a PIC32MX?

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • How to program a PIC32MX?

      Hello.

      How can i program a PIC32MX.

      I've tried to program the controller (using latest JLINK v7.94g), but i always get a error message: "Writing target memory failed."

      Is it even possible to program a pic32mx with the segger jlink, or can you just delete it?


      Here the commands:

      C:JLink.exe -device PIC32MX -if ICSP -speed 1000 -autoconnect 1 -CommanderScript pic32S.jlink

      The sript file is:

      Source Code

      1. ERASE
      2. LoadFile D:\SEGGER\Software\BPS191.hex
      3. EXIT

      The output is:
      ###########################################################
      J-Link Command File read successfully.
      Processing script file...
      J-Link>ERASE
      J-Link connection not established yet but required for command.
      Connecting to J-Link via USB...O.K.
      Firmware: J-Link Pro V4 compiled Sep 22 2022 15:00:37
      Hardware version: V4.00
      J-Link uptime (since boot): N/A (Not supported by this model)
      S/N: 17???????
      License(s): RDI, FlashBP, FlashDL, JFlash, GDB
      IP-Addr: DHCP (no addr. received yet)
      VTref=3.324V
      Target connection not established yet but required for command.
      Device "PIC32MX" selected.


      Connecting to target via ICSP
      TotalIRLen = 5, IRPrint = 0x01
      JTAG chain detection found 1 devices:
      #0 Id: 0x26A00053, IRLen: 05, Microchip MTAP
      Found PIC32 device with MIPS M4K core.

      CPU supports 6 code & 2 data breakpoints
      Memory zones:
      Zone: "Default" Description: Default access mode
      MIPS M4K identified.
      No address range specified, 'Erase Chip' will be executed
      'erase': Performing implicit reset & halt of MCU.
      PIC32 (2-wire-JTAG): Connection lost after reset. Entering ICSP mode to regain control over device.
      Erasing device...
      Erasing done.

      J-Link>LoadFile D:\SEGGER\Software\BPS191.hex
      'loadfile': Performing implicit reset & halt of MCU.
      PIC32 (2-wire-JTAG): Connection lost after reset. Entering ICSP mode to regain control over device.
      Downloading file [D:\SEGGER\Software\BPS191.hex]...
      Writing target memory failed.
      J-Link>EXIT

      Script processing completed.
      ############################################

      The post was edited 2 times, last by Forster ().

    • Hi,

      Well, you need to pass the correct name to J-Link…
      Not all devices share the same algorithm and flash size, so J-Link needs to know which device it is talking to, in order to have the correct algorithm selected.
      List of valid device names for PIC32MX family:
      segger.com/supported-devices/search/pic32mx


      BR
      Alex
      Please read the forum rules before posting.

      Keep in mind, this is *not* a support forum.
      Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
      Should you be entitled to support you can contact us via our support system: segger.com/ticket/

      Or you can contact us via e-mail.
    • Hi Alex.

      Thank you for the answer.

      Unfortunately, the used microcontroller ( PIC32MX130F128H ) is not yet in the list of supported derivatives.
      That's why I tried to do something with the general device specification ( PIC32MX ).

      Very unfortunate.
    • Even more unfortunate that you did not mention the exact device in use in the first place and that you were missing support,
      but instead let us guess and invest time into an answer that you already knew / probably expected...

      However, I invested some more time and checked for a quick solution:
      You should be able to use the PIC32MX130F128H by selecting "PIC32MX150F128B".
      From the debug & flash programming point of view, they should be compatible.

      Can you please give this a try and provide some feedback?
      If it works, we would add the PIC32MX130F128H "blindly" for the next version.


      BR
      Alex
      Please read the forum rules before posting.

      Keep in mind, this is *not* a support forum.
      Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
      Should you be entitled to support you can contact us via our support system: segger.com/ticket/

      Or you can contact us via e-mail.
    • Hi Alex.

      Thank you for the great support.

      I tested it, but unfortunately it doesn't work.


      Following is happend:


      I test this combinations:



      PIC32MX150F128B
      PIC32MX150F128C
      PIC32MX150F128D
      PIC32MX250F128B
      PIC32MX250F128C
      PIC32MX250F128D
      PIC32MX320F128H
      ****** Error: Failed to erase sectors 128 @ address 0x9FC00000 ((erase error))


      PIC32MX320F128L
      PIC32MX440F128L
      ****** Error: Failed to erase sectors 32 @ address 0x9FC00000 ((erase error))


      PIC32MX130F064B
      ****** Error: Failed to erase sectors 64 @ address 0x9FC00000 ((erase error))



      Here the complete message:



      C:\Program Files\SEGGER\JLink>jlink -device PIC32MX250F128D -if ICSP -speed 1000 -autoconnect 1
      SEGGER J-Link Commander V7.92q (Compiled Nov 23 2023 18:11:39)
      DLL version V7.92q, compiled Nov 23 2023 18:09:52


      Connecting to J-Link via USB...O.K.
      Firmware: J-Link Pro V4 compiled Sep 22 2022 15:00:37
      Hardware version: V4.00
      J-Link uptime (since boot): N/A (Not supported by this model)
      S/N: 17xxxxxxx
      License(s): RDI, FlashBP, FlashDL, JFlash, GDB
      IP-Addr: DHCP (no addr. received yet)
      VTref=3.294V
      Device "PIC32MX250F128D" selected.


      Connecting to target via ICSP
      TotalIRLen = 5, IRPrint = 0x01
      JTAG chain detection found 1 devices:
      #0 Id: 0x26A00053, IRLen: 05, Microchip MTAP
      Found PIC32 device with MIPS M4K core.
      Temporarily halting CPU for debug setup
      CPU supports 6 code & 2 data breakpoints
      Restarting CPU
      Memory zones:
      Zone: "Default" Description: Default access mode
      MIPS M4K identified.


      J-Link>erase
      No address range specified, 'Erase Chip' will be executed
      'erase': Performing implicit reset & halt of MCU.
      Erasing device...


      ****** Error: Failed to erase sectors 128 @ address 0x9FC00000 ((erase error))
      J-Link: Flash download: Total time needed: 2.748s (Prepare: 1.380s, Compare: 0.000s, Erase: 0.249s, Program: 0.000s, Verify: 0.000s, Restore: 1.117s)
      ERROR: Erase returned with error code -5.
      J-Link>

      ###############################################################

      Than i try the segger JLink with the Microchip studio. It says:
      Connecting to JLink Probe...
      Connection Failed
      Comm library returned an error code of -261, Could not find supported CPU.

      ###############################################################

      Than i use the microchip-studio to erase the device with a microchip snap programmer ( -> is working without problem) and disconnect the now erased device.

      ###############################################################

      After that i reconnect to the JLink.
      Now, with the "Pre-Erased" device, Jlink is now working a little bit ( but not with another NEW and unerased device !!!)



      C:\Program Files\SEGGER\JLink>jlink -device PIC32MX250F128D -if ICSP -speed 1000 -autoconnect 1
      SEGGER J-Link Commander V7.92q (Compiled Nov 23 2023 18:11:39)
      DLL version V7.92q, compiled Nov 23 2023 18:09:52


      Connecting to J-Link via USB...O.K.
      Firmware: J-Link Pro V4 compiled Sep 22 2022 15:00:37
      Hardware version: V4.00
      J-Link uptime (since boot): N/A (Not supported by this model)
      S/N: 17xxxxxxx
      License(s): RDI, FlashBP, FlashDL, JFlash, GDB
      IP-Addr: DHCP (no addr. received yet)
      VTref=3.300V
      Device "PIC32MX250F128D" selected.


      Connecting to target via ICSP
      TotalIRLen = 5, IRPrint = 0x01
      JTAG chain detection found 1 devices:
      #0 Id: 0x26A00053, IRLen: 05, Microchip MTAP
      Found PIC32 device with MIPS M4K core.
      Temporarily halting CPU for debug setup
      CPU supports 6 code & 2 data breakpoints
      Restarting CPU
      Memory zones:
      Zone: "Default" Description: Default access mode
      MIPS M4K identified.
      J-Link>erase
      No address range specified, 'Erase Chip' will be executed
      'erase': Performing implicit reset & halt of MCU.
      PIC32 (2-wire-JTAG): Connection lost after reset. Entering ICSP mode to regain control over device.
      Erasing device...
      J-Link: Flash download: Total time needed: 2.764s (Prepare: 1.386s, Compare: 0.000s, Erase: 0.260s, Program: 0.000s, Verify: 0.000s, Restore: 1.117s)
      Erasing done.
      J-Link>




      Now i try to programm the device eith the JLink:



      J-Link>loadfile d:bps191.hex
      'loadfile': Performing implicit reset & halt of MCU.
      PIC32 (2-wire-JTAG): Connection lost after reset. Entering ICSP mode to regain control over device.
      Downloading file [d:bps191.hex]...
      Programming data would disable ICSP debugging. Modified data to enable ICSP.
      Error while programming flash: Programming failed.
      J-Link>


      After that it was no longer possible to erase the device.