PIC Mplab XC8 EEPROM Read Null - pic

How to check if the eeprom at a particular address is null/empty or not. I'm using the PIC18F45Q43 and using eeprom_read() function.

Related

Can't define __BOOTLOADER for linker script of PIC24FJ128GC006

I am making a USB Bootloader for PIC24FJ128GC006 and I am going to map part of the flash memory for the Bootloader and the Application code.
I added the linker script from Microchip MLA v2015_08 usb device bootloader to my PIC24FJ code file.
In the linker file, the __BOOTLOADER must be defined in order to access the 0x400 address region.
#ifdef __BOOTLOADER
program (xr) : ORIGIN = 0x400, LENGTH = 0x35BE
#else
program (xr) : ORIGIN = 0x4002, LENGTH = 0x117F4
#endif
In the main.c of my bootloader code, I have already #define __BOOTLOADER, but when I program the bootloader code to the PIC using ICD3 and check the program memory by using the PIC Memory Views of MPLAB Window Toolbar, the data is written to the 0x4002 address and not in the 0x400.
What can be the problem?
Okay. I have solved my problem above. You should write #define __BOOTLOADER in the linker file, not in main.c.
Another problem has risen though. In my code file dashboard, it indicates there that I have used 97% of the program memory after defining the __BOOTLOADER. So my question is that, can I remove some codes in the linker file to decrease the used program memory? If yes, how can I know what to remove in the vector tables?

Get easy access to peripherals using arm-none-eabi-gdb and openocd

I use openocd, arm-none-eabi-gdb and STLinkV2-1 to debug STM32F411CE chip. I use also LL and CMSIS libraries. The problem is that to check the value of e.g. a pin I have to look up in the datasheet the register boundary addresses for the specific GPIO port (e.g. 0x4002 0000 - 0x4002 03FF for GPIOA) and then check whats the offset for the register I want to read (e.g. 0x10 for GPIOx_IDR). Then to check a specific bit I have to check once more in datasheet what's the offset for it in the register and calculate from hex value the value of the bit. So for gdb it will be:
(gdb) x 0x40020010
0x40020010: 0xa8280000
Is there an easier approach to get the value, by typing something like that:
get bit value in register GPIOA IDR
I couldn't find anything in openocd datasheet or in the Internet which answers my question.
I have found a solution.
CMSIS defines all the peripherals, so we can make use of it:
Compile the project with -gdwarf-4 -g3 gcc flags to use preprocessor macros within gdb
Run gdb:
arm-none-eabi-gdb -nw program.elf
Make use of CMSIS definitions: to check e.g. 3rd pin on PORTB used as input:
(gdb) p (GPIOB->IDR & GPIO_BSRR_BS_3)

Editing the pad control register has no effect

After reading the AM3359 Technical Reference manual, I saw that you can edit the pad control registers(Pin Mux). I tried editing these registers using devmem2 and it says that it successfully writes to it but upon reading the value again it is exactly the same.
I used the command sudo devmem2 0x44E10818 w 0x7 and returns
Value at address 0x44E10818 (0xb6f2c818): 0x31
Written 0x7; readback 0x7
but then I read it again and it says the value is: 0x31.
All I could think is that maybe there is something underlying in the linux kernel that is setting the values. What is causing the pin mux to hold its value?
From AM335x TRM I can see that:
0x44E10000 is the address of Control Module registers bank (from section 2 "Memory Map")
0x818 is conf_gpmc_ad6 (from section 9 "Control Module")
From AM335x datasheet I see that:
GPMC_AD6 pad is R9 ball (for ZCZ SoC, which you have on BBB)
From BBB Rev. A6 schematics I see that:
R9 ball is connected to MMC1_DAT6 line
MMC1_DAT6 line is connected to eMMC flash
From your question (using TRM) I can conclude that:
by default this pin is muxed in mmc1_dat6 mode
you are trying to remux it to gpio1_6 mode
So from this investigation I can say that you shouldn't remux that pin (even if it was possible), because it's needed to be muxed as mmc1_dat6 for eMMC to be accessible from your SoC.
If you are really needed to mux it as gpio1_6, be sure to change mux mode for it in device tree file first (and replace dtb file on BBB with new one). In that case you won't be able to use 8-bit mode for your eMMC, so you probably need to change this mode to 4-bit in device tree file as well.
References:
[1] AM3359 SoC documentation
[2] BeagleBone Black (Rev. A6) documentation (schematics, etc.)

Microchip ICSP PIC 32F Programming with ICD3- Secure Chip Vs Verify

A hex file is provided to the Microchip IPE programming tool and an ICD3 for a PIC 32F. The hex file includes an out-of-memory-map data location with a config bit set that sets a configuration register so tha the contents of ROM cannot be read withut erasing the chip.
When Using Microchips IPE tool, will an ICD 3 actually verify the PIC 32F chip and then secure it, or will it simply program the chip blindly in one step since the chip cannot be read back.
It will actually verify the chip, but it will program it bindly, believing that the hex is intended for that part.
The IPE checks for the appropriate part to set the fuses (config words). If it is on a different location than the assembled hex, you may run into problems like, for example, having a WDT running. So, if the hex was assembled for another part, it will work just the same.

PIC24F - Possible for data values to persist, even after the PIC is powered off?

I have a question regarding the persistence (storage) of data values in a PIC24F, even after the PIC has been turned off.
I have read through the datasheet(s), but am confused regarding the difference of the EEPROM and Flash memory.
For example, say I have a variable "x", is there a way for the value of "x" to persist even after the PIC has been shut off? I know programs can persist in the flash memory so long as the code is compiled in Stand Alone Operation (COE_OFF). However, I am specifically wondering about data values.
If I make the program memory and the memory for the data value non-volatile, will it persist even when the power is off?
Do I need to declare the value as "static", example: static int x; ?
Or am I wrong and there isn't any way for a data value to persist even after the power has been turned off?
Thanks for the help and clarifications!
You must write to flash in pages, using the TBLWTL and TBLWTH instructions, as you have read in the datasheet for your device. This is typically for updating your software through a bootloader, and it does not sound like this is what you are after.
To access the EEPROM you can do it in smaller units, and there are compiler convenience macros for declaring where in the memory map a variable should live. You can specify that the variable lives in EEPROM and the compiler will generate instructions for accessing and updating that for you. You can also use the compiler intrinsics or the TBL instructions for reading it directly.
The declaration will probably look something like:
unsigned __attribute__((space(eedata), aligned(2)) my_eeprom_variable;
Look at the generated assembler to see what the compiler does when you access the variable.
Declaring a variable static only has traditional C semantics; it controls the scope of the variable and the initialisation rules.
Contents of registers and RAM variables are lost when power is turned off. Flash and EEPROM are both persistent. Flash can only be erased in large blocks - 128K and up depending on the type that you have. EEPROM words can be individually read or written. If you have EEPROM, that's your best bet for saving a small amount of data. Usually you have to read and write EEPROM serially.
thanks for the responses!
After some other suggestions I read through the MPLAB C30 Compiler datasheet again, and found the "persistent" attribute.
Per the datasheet:
"The persistent attribute specifies that the variable should not be initialized or cleared at startup. A variable with the persistent attribute could be used to store state information that will remain valid after a device reset."
I'm going to try using this to see if it will work.

Resources