Skip to content

Commit

Permalink
Adds datamemory write and read implementation to the CC13xx device dr…
Browse files Browse the repository at this point in the history
…iver.
  • Loading branch information
p-weber committed Nov 24, 2017
1 parent 401f7ab commit 7504c35
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 0 deletions.
91 changes: 91 additions & 0 deletions target/arch/arm/cm3/ti/device/cc13xx/sf_mcu.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@

/* Stack includes */
#include "sf_mcu.h"
#include "target_conf.h"
/* Chip specific */
#include "driverlib/pwr_ctrl.h"
#include "driverlib/flash.h"
#include "driverlib/vims.h"
#include "driverlib/sys_ctrl.h"
#include "driverlib/interrupt.h"

Expand Down Expand Up @@ -76,6 +79,94 @@ void sf_mcu_reset(void)
SysCtrlSystemReset();
} /* sf_mcu_reset() */

/*============================================================================*/
/*! sf_mcu_datamemory_write() */
/*============================================================================*/
uint16_t sf_mcu_datamemory_write(uint8_t *pc_data, uint16_t i_len, uint32_t l_addr)
{
/* Counter variable. */
uint16_t i;
/* Start of the segment to write into. */
uint8_t *pc_memory;
/* Number of written bytes */
uint16_t i_return = 0x00U;
/* Array to save the flash content before erasing the flash */
static uint8_t ac_flashPage[MCU_INFOFLASH_SIZE];
/* Address of the first segment. */
uint32_t l_addrSegmStart;

/* Check the input parameters */
if((i_len > 0x00U) && (NULL != pc_data) &&
((l_addr + i_len) <= MCU_INFOFLASH_SIZE))
{
/* Find the start of the flash page. */
l_addrSegmStart = l_addr + TARGET_NVM_START_ADDR;
while((l_addrSegmStart % SECTOR_SIZE) != 0)
{
l_addrSegmStart--;
} /* while */

/* Calculates the start address to write in.*/
l_addr %= SECTOR_SIZE;

/* Disable the cache */
VIMSModeSet(VIMS_BASE, VIMS_MODE_DISABLED);
while(VIMSModeGet(VIMS_BASE) != VIMS_MODE_DISABLED);

/* Check if the flash is protected */
if(FlashProtectionGet(l_addr) != FLASH_WRITE_PROTECT)
{
/* Set the local pointer to the start of the flash page */
pc_memory = (uint8_t*) l_addrSegmStart;

/* Store the flash data in local array */
for(i = 0x00U; i < MCU_INFOFLASH_SIZE; i++)
{
ac_flashPage[i] = pc_memory[i];
} /* for */

/* Updates the current flash page. */
for(i = 0x00U; i < i_len; i++)
{
ac_flashPage[(l_addr + i)] = pc_data[i];
} /* for */

/* Erase and rewrite the flash */
if (FlashSectorErase(l_addrSegmStart) == FAPI_STATUS_SUCCESS)
{
if(FlashProgram(ac_flashPage, l_addrSegmStart, MCU_INFOFLASH_SIZE) == FAPI_STATUS_SUCCESS)
{
i_return = i_len;
}/* if */
}
}/* if */
/* Re-enable the cache */
VIMSModeSet(VIMS_BASE, VIMS_MODE_ENABLED);
}/* if */

return i_return;
} /* sf_mcu_datamemory_write() */

/*============================================================================*/
/*! sf_mcu_datamemory_read() */
/*============================================================================*/
uint16_t sf_mcu_datamemory_read(uint8_t *pc_data, uint16_t i_len, uint32_t l_addr)
{
/* Counter variable. */
uint16_t i;
/* Pointer to the segment to read from. */
uint8_t *pc_memory;

pc_memory = ((uint8_t*) (TARGET_NVM_START_ADDR)) + l_addr;

for(i = 0x00U; i < i_len ;i++)
{
pc_data[i] = pc_memory[i];
} /* for */

return i_len;
} /* sf_mcu_datamemory_read() */

/*============================================================================*/
/*! sf_mcu_interrutpEnable() */
/*============================================================================*/
Expand Down
32 changes: 32 additions & 0 deletions target/arch/arm/cm3/ti/device/cc13xx/sf_mcu.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,17 @@
/*==============================================================================
DEFINES
==============================================================================*/
/*========================= FLASH ============================================*/
/*! Calculate the size of the nvm space available for the device. Note that the
available space and the SECTOR_SIZE is not the same. To save RAM the
available space is normally smaler than a flash page! */
#define MCU_INFOFLASH_SIZE (TARGET_NVM_END_ADDR - TARGET_NVM_START_ADDR)

/* Currently it is only supported to write on more than one page so this check
is necessary */
#if (MCU_INFOFLASH_SIZE > SECTOR_SIZE)
#error Currently we do not support more than one flash page
#endif /* (MCU_INFOFLASH_SIZE > SECTOR_SIZE) */
/*==============================================================================
FUNCTIONS
==============================================================================*/
Expand All @@ -53,6 +63,28 @@ bool sf_mcu_init(void);
/*============================================================================*/
void sf_mcu_reset(void);

/*============================================================================*/
/*!
* @brief Writes bytes into the data memory.
* @param l_addr Start address of the memory to write into.
* @param *pc_data Bytes to write into the data memory.
* @param i_len Number of bytes to write.
* @return Returns the number of bytes written.
*/
/*============================================================================*/
uint16_t sf_mcu_datamemory_write(uint8_t *pc_data, uint16_t i_len, uint32_t l_addr);

/*============================================================================*/
/*!
* @brief Reads bytes from the data memory.
* @param l_addr Address of the memory to read out.
* @param *pc_data Memory to write the read data into.
* @param i_len Number of bytes to read.
* @return Returns the number of bytes read.
*/
/*============================================================================*/
uint16_t sf_mcu_datamemory_read(uint8_t *pc_data, uint16_t i_len, uint32_t l_addr);

/*============================================================================*/
/*!
* @brief Enable the interrupts.
Expand Down
13 changes: 13 additions & 0 deletions target/mcu/cc13xx/target_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@
/*! Needed for TI driverlib. */
#define RFC_INCLUDE_GFSK

/*========================= NVM MEMORY =======================================*/
/*! Flash defines: For the CC1350 one flash page is 4096byte */
#define SECTOR_SIZE 4096U
/*! The CC1350 has at least 32 flash pages (0-31). We will write our stuff on the
penultimate page. */
#define SECTOR_TO_USE 30U
/*! The absolute start address of the nvm memory. */
#define TARGET_NVM_START_ADDR (FLASHMEM_BASE + \
(SECTOR_TO_USE * SECTOR_SIZE))
/*! The absolute end-address of the nvm memory. (The last addressable byte).
For now the usable memory is limited to 512 byte. */
#define TARGET_NVM_END_ADDR TARGET_NVM_START_ADDR + 512U

/*========================= PLATFROM =========================================*/
/*! Platform interfaces: Definition of RX pin and TX pin. */
#ifndef UART_IOID_RXD
Expand Down

0 comments on commit 7504c35

Please sign in to comment.