Author Topic: Programming PIC32MX210F016B  (Read 3455 times)

0 Members and 1 Guest are viewing this topic.

Offline vlad777Topic starter

  • Frequent Contributor
  • **
  • Posts: 350
  • Country: 00
Programming PIC32MX210F016B
« on: December 04, 2019, 11:38:08 pm »
Hi,

I have used the MCC gui to create a small code that blinks a led.

I am using mplabx snap.

It works when i press "debug main project"
but it doesn't work when i press "run main project"
(doesn't blink the led)

(Everything builds successfully, in all cases.
 and snap output is : Programming/Verify complete
)

MPLAB X IDE v5.20
xc32 v2.30
Microchip PIC32MX210F016B

Code: [Select]
// Configuration bits: selected in the GUI

// DEVCFG3
#pragma config PMDL1WAY = ON    // Peripheral Module Disable Configuration->Allow only one reconfiguration
#pragma config IOL1WAY = ON    // Peripheral Pin Select Configuration->Allow only one reconfiguration
#pragma config FUSBIDIO = OFF    // USB USID Selection->Controlled by Port Function
#pragma config FVBUSONIO = OFF    // USB VBUS ON Selection->Controlled by Port Function

// DEVCFG2
#pragma config FPLLIDIV = DIV_12    // PLL Input Divider->12x Divider
#pragma config FPLLMUL = MUL_24    // PLL Multiplier->24x Multiplier
#pragma config UPLLIDIV = DIV_12    // USB PLL Input Divider->12x Divider
#pragma config UPLLEN = OFF    // USB PLL Enable->Disabled and Bypassed
#pragma config FPLLODIV = DIV_256    // System PLL Output Clock Divider->PLL Divide by 256

// DEVCFG1
#pragma config FNOSC = FRCDIV    // Oscillator Selection Bits->Fast RC Osc w/Div-by-N (FRCDIV)
#pragma config FSOSCEN = OFF    // Secondary Oscillator Enable->Disabled
#pragma config IESO = OFF    // Internal/External Switch Over->Disabled
#pragma config POSCMOD = OFF    // Primary Oscillator Configuration->Primary osc disabled
#pragma config OSCIOFNC = OFF    // CLKO Output Signal Active on the OSCO Pin->Disabled
#pragma config FPBDIV = DIV_2    // Peripheral Clock Divisor->Pb_Clk is Sys_Clk/2
#pragma config FCKSM = CSDCMD    // Clock Switching and Monitor Selection->Clock Switch Disable, FSCM Disabled
#pragma config WDTPS = PS1048576    // Watchdog Timer Postscaler->1:1048576
#pragma config WINDIS = OFF    // Watchdog Timer Window Enable->Watchdog Timer is in Non-Window Mode
#pragma config FWDTEN = OFF    // Watchdog Timer Enable->WDT Disabled (SWDTEN Bit Controls)
#pragma config FWDTWINSZ = WINSZ_25    // Watchdog Timer Window Size->Window Size is 25%

// DEVCFG0
#pragma config DEBUG = OFF    // Background Debugger Enable->Debugger is Disabled
#pragma config JTAGEN = OFF    // JTAG Enable->JTAG Disabled
#pragma config ICESEL = ICS_PGx1    // ICE/ICD Comm Channel Select->Communicate on PGEC1/PGED1
#pragma config PWP = OFF    // Program Flash Write Protect->Disable
#pragma config BWP = OFF    // Boot Flash Write Protect bit->Protection Disabled
#pragma config CP = OFF    // Code Protect->Protection Disabled



Code: [Select]

#include "mcc_generated_files/mcc.h"


void mydelay(){
    int n=100000;
    while(n>0)n--;
}
/*
                         Main application
 */
int main(void)
{
    // initialize the device
    SYSTEM_Initialize();

    IO_RB8_SetDigitalOutput(); //functions generated by the gui
    IO_RB5_SetDigitalOutput();
   
    while (1)
    {
        // Add your application code
       
        IO_RB8_Toggle(); //functions generated by the gui
        IO_RB5_Toggle();
        mydelay();
    }

    return -1;
}



Many thanks.
« Last Edit: December 04, 2019, 11:40:41 pm by vlad777 »
Mind over matter. Pain over mind. Boss over pain.
-------------------------
 

Offline NorthGuy

  • Super Contributor
  • ***
  • Posts: 3146
  • Country: ca
Re: Programming PIC32MX210F016B
« Reply #1 on: December 05, 2019, 10:14:57 pm »
Insert a delay between toggles. Otherwise it's too fast to see.
 

Offline vlad777Topic starter

  • Frequent Contributor
  • **
  • Posts: 350
  • Country: 00
Re: Programming PIC32MX210F016B
« Reply #2 on: December 05, 2019, 10:49:03 pm »
Insert a delay between toggles. Otherwise it's too fast to see.


I do have mydelay(); called.
(two toggle calls are for different pins.)

The led is full off, in run mode, but blinking normally in debug mode.
« Last Edit: December 05, 2019, 10:51:00 pm by vlad777 »
Mind over matter. Pain over mind. Boss over pain.
-------------------------
 

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5319
  • Country: gb
Re: Programming PIC32MX210F016B
« Reply #3 on: December 05, 2019, 10:57:17 pm »
Do you have a pull up on MCLR?

 

Offline vlad777Topic starter

  • Frequent Contributor
  • **
  • Posts: 350
  • Country: 00
Re: Programming PIC32MX210F016B
« Reply #4 on: December 05, 2019, 11:39:22 pm »
Mind over matter. Pain over mind. Boss over pain.
-------------------------
 

Offline andersm

  • Super Contributor
  • ***
  • Posts: 1198
  • Country: fi
Re: Programming PIC32MX210F016B
« Reply #5 on: December 05, 2019, 11:53:49 pm »
With compiler optimizations enabled, that kind of delay loop will be completely optimized away. The quick hack fix is to make the counter variable volatile, but it's much better to use a timer.

Offline vlad777Topic starter

  • Frequent Contributor
  • **
  • Posts: 350
  • Country: 00
Re: Programming PIC32MX210F016B
« Reply #6 on: December 06, 2019, 12:18:08 am »
Do I need to worry about the bootloader?

It could be missing.
I didn't set the config for the bootloader right (for example maybe it uses some peripherial)
I need to put the pullup or pulldown on the pin that the bootloader probes at startup.
« Last Edit: December 06, 2019, 12:19:55 am by vlad777 »
Mind over matter. Pain over mind. Boss over pain.
-------------------------
 

Offline NorthGuy

  • Super Contributor
  • ***
  • Posts: 3146
  • Country: ca
Re: Programming PIC32MX210F016B
« Reply #7 on: December 06, 2019, 12:21:22 am »
The led is full off, in run mode, but blinking normally in debug mode.

Even if delays didn't work LED wuldn't be constantly off.

Check the voltage on the MCLR pin. Must be VDD. If 0, remove the programmer and see if LEDs blink.
 

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5319
  • Country: gb
Re: Programming PIC32MX210F016B
« Reply #8 on: December 06, 2019, 12:31:09 am »
What boot loader?
 

Offline vlad777Topic starter

  • Frequent Contributor
  • **
  • Posts: 350
  • Country: 00
Re: Programming PIC32MX210F016B
« Reply #9 on: December 06, 2019, 12:39:20 am »
What boot loader?

this chip has a boot loader flash and I don't know if it is properly programmed:
boot flash address:  0x1FC00000
program flash:          0x1D000000


snap output is:

Erasing...

The following memory area(s) will be programmed:
program memory: start address = 0x1d000000, end address = 0x1d000fff
configuration memory
boot config memory

Programming/Verify complete
Mind over matter. Pain over mind. Boss over pain.
-------------------------
 

Offline cv007

  • Frequent Contributor
  • **
  • Posts: 826
Re: Programming PIC32MX210F016B
« Reply #10 on: December 06, 2019, 03:48:04 am »
>Do I need to worry about the bootloader?

There is no bootloader, unless you put one in, and if you were at that point you would have already jumped through a number of hoops to get there. There is a little chunk of flash that is designated as 'boot flash memory', and you don't really have to deal with it. The linker will place some startup code in there, and when debugging some of that area is used for the debug code.

I don't have the answer, but when debugging there is added code that is put into the mcu as already indicated but your app code should be the same and it should be seamless to run debug code or 'release' code (and no separate config for each). If the compiler was optimizing out your delay loop, it would do it in both cases which probably just indicates your optimization level is at a default level and is leaving it alone.

I'm not sure why your config bits include the DEBUG pragma, as I think the ide turns that fuse bit on/off depending on whether you are debugging or not.

I see you don't use the power pin on the snap (pin 2), even though it does not supply power through that pin it is used to set the two programming pin levels. I would probably hook it up even it if seems happy at the moment without it.

You can also disconnect the mclr line from the snap, just to see if for some reason its holding the reset line low. Probably not, but takes 2 seconds to check.
 

Offline vlad777Topic starter

  • Frequent Contributor
  • **
  • Posts: 350
  • Country: 00
Re: Programming PIC32MX210F016B
« Reply #11 on: December 06, 2019, 10:30:17 pm »
I have found a solution.
This guy didn't touch configuration bits and it works.
I tried it and it works for me too, which proves that I have bad config in the program.




Edit: The issue was the line: #pragma config DEBUG = OFF 
         I just comment it out and it works.
« Last Edit: December 07, 2019, 02:59:51 am by vlad777 »
Mind over matter. Pain over mind. Boss over pain.
-------------------------
 

Offline vlad777Topic starter

  • Frequent Contributor
  • **
  • Posts: 350
  • Country: 00
Re: Programming PIC32MX210F016B
« Reply #12 on: December 06, 2019, 10:37:04 pm »
Here is a blinker in MIPS assembly :

Code: [Select]

   # led on pin 3 , mclr pullup 1k
   
.global main
   
.data
    tris: .word 0xbf886010
    lat:  .word 0xbf886030
.text
   

    main:
   
    lw $t1,tris
    lw $t2,lat
   
    addi $t3,$zero,0b11111101
    addi $t4,$zero,2
   
    sb $t3,0($t1)
    sb $t4,0($t2)
   
    loopn1:
   
    li $t0,300000
   
    loop1:
   
    addi $t0,$t0,-1

    bne $t0,$zero,loop1
   
    sb $zero,0($t2)
   
    loopn2:
   
    li $t0,3000000
   
    loop2:
   
    addi $t0,$t0,-1

    bne $t0,$zero,loop2
   
    sb $t4,0($t2)
   
    j loopn1


Mind over matter. Pain over mind. Boss over pain.
-------------------------
 

Offline vlad777Topic starter

  • Frequent Contributor
  • **
  • Posts: 350
  • Country: 00
Re: Programming PIC32MX210F016B
« Reply #13 on: December 07, 2019, 08:25:49 am »
I want to get to a .hex file, from MIPS assembler file, without using microchip technology.

Is there a gcc gnu assembler that I can use with this chip?

This maybe ?
https://codescape.mips.com/components/toolchain/2019.09-01/index.html

Or this?
https://gcc.gnu.org/

What do you recommend?
Many thanks.

PS:
I still just want to blink a led.
But now I would have to setup vector table, maybe segments, maybe starting stack address.
And I suppose I would burn to boot loader area.
« Last Edit: December 07, 2019, 08:36:05 am by vlad777 »
Mind over matter. Pain over mind. Boss over pain.
-------------------------
 

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5319
  • Country: gb
Re: Programming PIC32MX210F016B
« Reply #14 on: December 07, 2019, 03:13:32 pm »
I think you’re trying to run before you can walk.

I cannot recommend MCC for a dozen+ reasons, but mostly that the code it generates is bug ridden and also it’s hard to maintain because it doesn’t allow separation of user code from machine generated code.

What produced the #pragma config DEBUG=OFF?

A blinky for this device should take under ten minutes to code up if you ignore MCC.

Not setting any config bits risks the watchdog reseting your device frequently.

Why are you trying to avoid the Microchip toolchain? (MCC excepted which is a pile of sh!t).
 

Offline andersm

  • Super Contributor
  • ***
  • Posts: 1198
  • Country: fi
Re: Programming PIC32MX210F016B
« Reply #15 on: December 07, 2019, 05:56:41 pm »
The GNU assembler is part of binutils, not GCC. It'll work, but making everything from scratch is a lot more involved for PIC32Ms than for most other devices.

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5319
  • Country: gb
Re: Programming PIC32MX210F016B
« Reply #16 on: December 07, 2019, 06:58:05 pm »
I am away in Japan at the moment, without a scope, but I do have a Microstick II with me and a PIC32MX170F256B which is kinda the same family.

The following toggles RA0 every second or so. I specified the processor to be PIC32MX210F016B and overrode the processor warning.

One further thing, if you're intending to use the USB functionality, I wish you luck fitting a stack inside this chip. You really need the PIC32MX220F032B at a minimum, and even then there's not much left over for application code, let alone a bootloader.

Code: [Select]

// PIC32MX210F016B Configuration Bit Settings

// 'C' source line config statements

// DEVCFG3
#pragma config USERID = 0xFFFF          // Enter Hexadecimal value (Enter Hexadecimal value)
#pragma config PMDL1WAY = OFF           // Peripheral Module Disable Configuration (Allow multiple reconfigurations)
#pragma config IOL1WAY = OFF            // Peripheral Pin Select Configuration (Allow multiple reconfigurations)
#pragma config FUSBIDIO = OFF           // USB USID Selection (Controlled by Port Function)
#pragma config FVBUSONIO = OFF          // USB VBUS ON Selection (Controlled by Port Function)

// DEVCFG2
#pragma config FPLLIDIV = DIV_12        // PLL Input Divider (12x Divider)
#pragma config FPLLMUL = MUL_24         // PLL Multiplier (24x Multiplier)
#pragma config UPLLIDIV = DIV_12        // USB PLL Input Divider (12x Divider)
#pragma config UPLLEN = OFF             // USB PLL Enable (Disabled and Bypassed)
#pragma config FPLLODIV = DIV_256       // System PLL Output Clock Divider (PLL Divide by 256)

// DEVCFG1
#pragma config FNOSC = FRC              // Oscillator Selection Bits (Fast RC Osc (FRC))
#pragma config FSOSCEN = OFF            // Secondary Oscillator Enable (Disabled)
#pragma config IESO = OFF               // Internal/External Switch Over (Disabled)
#pragma config POSCMOD = OFF            // Primary Oscillator Configuration (Primary osc disabled)
#pragma config OSCIOFNC = OFF           // CLKO Output Signal Active on the OSCO Pin (Disabled)
#pragma config FPBDIV = DIV_1           // Peripheral Clock Divisor (Pb_Clk is Sys_Clk/1)
#pragma config FCKSM = CSECMD           // Clock Switching and Monitor Selection (Clock Switch Enable, FSCM Disabled)
#pragma config WDTPS = PS1048576        // Watchdog Timer Postscaler (1:1048576)
#pragma config WINDIS = OFF             // Watchdog Timer Window Enable (Watchdog Timer is in Non-Window Mode)
#pragma config FWDTEN = OFF             // Watchdog Timer Enable (WDT Disabled (SWDTEN Bit Controls))
#pragma config FWDTWINSZ = WINSZ_25     // Watchdog Timer Window Size (Window Size is 25%)

// DEVCFG0
#pragma config JTAGEN = OFF             // JTAG Enable (JTAG Disabled)
#pragma config ICESEL = ICS_PGx1        // ICE/ICD Comm Channel Select (Communicate on PGEC1/PGED1)
#pragma config PWP = OFF                // Program Flash Write Protect (Disable)
#pragma config BWP = OFF                // Boot Flash Write Protect bit (Protection Disabled)
#pragma config CP = OFF                 // Code Protect (Protection Disabled)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#include <xc.h>
#include <stdint.h>

#define CLOCKFREQ 8000000

void MyDelayMS(uint32_t u32)
{
    while (u32--)
    {
        uint32_t u32Inner=CLOCKFREQ/8000;
       
        while (u32Inner--)
        {
            Nop();
            Nop();
            Nop();
        }
        Nop();
    }
}
int main(void)
{
    BMXCONbits.BMXWSDRM=0; // Zero RAM wait states
   
    TRISAbits.TRISA0=0; // RA0 digital output
    ANSELAbits.ANSA0=0;
   
    while (1)
    {
        LATAbits.LATA0=1;
        MyDelayMS(1000);
        LATAbits.LATA0=0;
        MyDelayMS(1000);
        Nop();
    }
    return 0;
}

« Last Edit: December 07, 2019, 07:15:58 pm by Howardlong »
 

Offline vlad777Topic starter

  • Frequent Contributor
  • **
  • Posts: 350
  • Country: 00
Re: Programming PIC32MX210F016B
« Reply #17 on: December 08, 2019, 12:43:03 am »
What produced the #pragma config DEBUG=OFF?

MCC produced it.
Mind over matter. Pain over mind. Boss over pain.
-------------------------
 

Offline vlad777Topic starter

  • Frequent Contributor
  • **
  • Posts: 350
  • Country: 00
Re: Programming PIC32MX210F016B
« Reply #18 on: December 08, 2019, 12:52:56 am »
So as I understand ,I am suppose to put the code at the address 0x1fc00000.
But if I use the .org directive i get 500MB of zeroes in my file.

So it seems in the end I have to use linker scripts, which I was hoping to avoid.

What would be the simplest linker script (replacing the .org directive)
for the assembly program that I posted above in a previous post.


BTW I am using Codescape GNU Toolchain

Code: [Select]
"I:\mips-mti-elf\2019.09-01\bin\mips-mti-elf-as" -march=mips32r2 -EL  main01.s -o pic32mx.o

"I:\mips-mti-elf\2019.09-01\bin\mips-mti-elf-objcopy"  -O ihex pic32mx.o pic32mx.hex

"I:\mips-mti-elf\2019.09-01\bin\mips-mti-elf-objdump" -D pic32mx.o >disasm.txt
pause
« Last Edit: December 08, 2019, 12:58:55 am by vlad777 »
Mind over matter. Pain over mind. Boss over pain.
-------------------------
 

Offline andersm

  • Super Contributor
  • ***
  • Posts: 1198
  • Country: fi
Re: Programming PIC32MX210F016B
« Reply #19 on: December 08, 2019, 01:59:38 am »
So as I understand ,I am suppose to put the code at the address 0x1fc00000.
Note that that is the physical address, but the CPU always uses virtual addresses (peripherals, like DMA, or the flash controller, use physical addresses). MIPS CPUs always start in KSEG1, so the code must be compiled to start at address 0xBFC00000.

Quote
What would be the simplest linker script (replacing the .org directive)
for the assembly program that I posted above in a previous post.
You need to define some memory regions, and then define output sections to which you map the input sections.

I do strongly recommend examining the linker scripts and startup code that ships with XC32. Try to explain what they do, and why.

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5319
  • Country: gb
Re: Programming PIC32MX210F016B
« Reply #20 on: December 08, 2019, 06:06:49 am »
What produced the #pragma config DEBUG=OFF?

MCC produced it.

I rest my case m’lud. MCC is indeed a bug ridden pile of sh!t.
 

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5319
  • Country: gb
Re: Programming PIC32MX210F016B
« Reply #21 on: December 08, 2019, 06:13:30 am »

BTW I am using Codescape GNU Toolchain


You are much more likely to get community support If you stick to MPLAB X and XC32. (And forget about MCC).

I popped into Akizuki Denshi in Akihabara an hour or so ago and picked up your exact part when I was in there. I can help you if you stick to MPLAB X and XC32.
 

Offline vlad777Topic starter

  • Frequent Contributor
  • **
  • Posts: 350
  • Country: 00
Re: Programming PIC32MX210F016B
« Reply #22 on: December 08, 2019, 07:11:31 am »

BTW I am using Codescape GNU Toolchain


You are much more likely to get community support If you stick to MPLAB X and XC32. (And forget about MCC).

I popped into Akizuki Denshi in Akihabara an hour or so ago and picked up your exact part when I was in there. I can help you if you stick to MPLAB X and XC32.


I am grateful that you want to help me. Maybe I should have explained my objective earlier.
I don't have a project in mind for this chip. Few days ago I was experimenting with NXP LPC810M021FN8FP part.
I won't go very specific with any of them , I am just getting a broad picture of software and hardware that different companies offer.
And learning just a little bit of MIPS and ARM assembly languages and comparing them to each other and to x86.


EDIT:
In the past I played with PWM, timers, UART and USB.
Maybe I'll try out ADC with this chip using MPLAB,
but frist I want to make a blinker with this other toolchain.

« Last Edit: December 08, 2019, 07:47:50 am by vlad777 »
Mind over matter. Pain over mind. Boss over pain.
-------------------------
 

Offline vlad777Topic starter

  • Frequent Contributor
  • **
  • Posts: 350
  • Country: 00
Re: Programming PIC32MX210F016B
« Reply #23 on: December 08, 2019, 11:54:22 am »
I got the blinker working.
I had to use one xc32 command:

"I:\Microchip\xc32\v2.30\bin\xc32-bin2hex" -v -i pic32mx.elf

-i, --virtual      use virtual addresses

mips-mti-elf-objcopy doesn't understand virtual addresses.
Mind over matter. Pain over mind. Boss over pain.
-------------------------
 

Offline andersm

  • Super Contributor
  • ***
  • Posts: 1198
  • Country: fi
Re: Programming PIC32MX210F016B
« Reply #24 on: December 08, 2019, 01:41:47 pm »
You can specify a separate virtual address and load addess for each output section in the linker script. Objcopy also has some options for adjusting section VMA and LMA.


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf