Author: AH_96 Version: **
Translation - Japanese: PSoC 4 IDAC のワンタイム オートキャリブレーション - KBA229095- Community Translated (JA)
Is it possible to obtain the IDAC value from autocalibration once while programming and use it during subsequent power-up in PSoC® 4?
Yes, it is possible to obtain the value from autocalibration and use the same value for the application without manually configuring each board. This can be implemented using the bootloader architecture.
Upon power-on reset, the bootloader will run first. The bootloader firmware runs the autocalibration algorithm and the IDAC value, obtained by using the CapSense_GetParam API, can be stored in flash. Once the autocalibration is complete, user can load the bootloadable application. The Bootloadable application then reads the stored data and sets the IDAC value using the CapSense_SetParam API. Both the APIs (CapSense_GetParam and CapSense_SetParam) must be called after CapSense_Start().
If the bootloader project need not bootload the new application, you can configure the communication component to Custom Interface and manually define the following five bootloader functions:
- void CyBtldrCommStart(void)
- void CyBtldrCommStop(void)
- void CyBtldrCommReset(void)
- cystatus CyBtldrCommWrite(uint8* buffer, uint16 size, uint16* count, uint8 timeOut)
- cystatus CyBtldrCommRead (uint8* buffer, uint16 size, uint16* count, uint8 timeOut)
Figure 1: Bootloader - selecting Communication component
Writing to the bootloadable flash area contents, could, however, result in bootloadable checksum validation failure. Therefore, the IDAC values need to be placed in the memory section called “checksum exclude region”. It is a memory region at the end of the Bootloadable application that is not used in the checksum verification. The size of the checksum exclude section can be set in the Bootloadable component configuration window. It is recommended to configure the size aligned to the flash row boundary. Refer to appropriate device datasheet for flash row size. This allows updating the checksum exclude section without changing the data in the code and data sections.
The IDAC value is an 8-bit value. Therefore, depending on the number of sensors and flash row size, the appropriate checksum exclude area size needs to be set in the bootloadable component configuration as shown in Figure 3.
Figure 3: Bootloadable - specifying checksum exclude
This will add a checksum exclude section in the linker script of the size mentioned in the GUI. While writing the IDAC value in the bootloader project, the data needs to be written in the checksum exclude region allocated in the bootloadable application. The macro, CY_FLASH_NUMBER_ROWS, will return the total number of rows of flash; this needs to be subtracted with the number of rows reserved for checksum exclude+1 (The last row is metadata and should not be modified. Therefore, an extra row of flash must be left).
Data can be written into the flash by using the API CySysFlashWriteRow, which returns CY_SYS_FLASH_SUCCESS if the operation was successful.
Bootloader code snippet:
//define the row for writing the IDAC value. In this case, 2 rows of flash were reserved therefore, data must
//be written in the third row from last
#define CY_TEST_FLASH_ROW (CY_FLASH_NUMBER_ROWS - 3u)
//code for acquiring IDAC value
data = (uint8) val;
data = (uint8)val;
//Writing data into flash
returnValue = CySysFlashWriteRow(CY_TEST_FLASH_ROW, data);
if (returnValue != CY_SYS_FLASH_SUCCESS)
//Run the bootloadable application
In the bootloadable project, data can be read directly by accessing the flash content using pointers.
//Absolute address of flash row
#define CY_TEST_FLASH_ADDR (CY_TEST_FLASH_ROW * CY_FLASH_SIZEOF_ROW)
for (i = 0u; i < 2; i++)
source = (*((uint8 *) (CY_TEST_FLASH_ADDR + i)));
/* Check if source and destination values are equal */
data[i] = source;
imodval = data;
icompval = data;
Bootloader component data sheet