Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • card10/firmware
  • annejan/firmware
  • astro/firmware
  • fpletz/firmware
  • gerd/firmware
  • fleur/firmware
  • swym/firmware
  • l/firmware
  • uberardy/firmware
  • wink/firmware
  • madonius/firmware
  • mot/firmware
  • filid/firmware
  • q3k/firmware
  • hauke/firmware
  • Woazboat/firmware
  • pink/firmware
  • mossmann/firmware
  • omniskop/firmware
  • zenox/firmware
  • trilader/firmware
  • Danukeru/firmware
  • shoragan/firmware
  • zlatko/firmware
  • sistason/firmware
  • datenwolf/firmware
  • bene/firmware
  • amedee/firmware
  • martinling/firmware
  • griffon/firmware
  • chris007/firmware
  • adisbladis/firmware
  • dbrgn/firmware
  • jelly/firmware
  • rnestler/firmware
  • mh/firmware
  • ln/firmware
  • penguineer/firmware
  • monkeydom/firmware
  • jens/firmware
  • jnaulty/firmware
  • jeffmakes/firmware
  • marekventur/firmware
  • pete/firmware
  • h2obrain/firmware
  • DooMMasteR/firmware
  • jackie/firmware
  • prof_r/firmware
  • Draradech/firmware
  • Kartoffel/firmware
  • hinerk/firmware
  • abbradar/firmware
  • JustTB/firmware
  • LuKaRo/firmware
  • iggy/firmware
  • ente/firmware
  • flgr/firmware
  • Lorphos/firmware
  • matejo/firmware
  • ceddral7/firmware
  • danb/firmware
  • joshi/firmware
  • melle/firmware
  • fitch/firmware
  • deurknop/firmware
  • sargon/firmware
  • markus/firmware
  • kloenk/firmware
  • lucaswerkmeister/firmware
  • derf/firmware
  • meh/firmware
  • dx/card10-firmware
  • torben/firmware
  • yuvadm/firmware
  • AndyBS/firmware
  • klausdieter1/firmware
  • katzenparadoxon/firmware
  • xiretza/firmware
  • ole/firmware
  • techy/firmware
  • thor77/firmware
  • TilCreator/firmware
  • fuchsi/firmware
  • dos/firmware
  • yrlf/firmware
  • PetePriority/firmware
  • SuperVirus/firmware
  • sur5r/firmware
  • tazz/firmware
  • Alienmaster/firmware
  • flo_h/firmware
  • baldo/firmware
  • mmu_man/firmware
  • Foaly/firmware
  • sodoku/firmware
  • Guinness/firmware
  • ssp/firmware
  • led02/firmware
  • Stormwind/firmware
  • arist/firmware
  • coon/firmware
  • mdik/firmware
  • pippin/firmware
  • royrobotiks/firmware
  • zigot83/firmware
  • mo_k/firmware
106 results
Show changes
Showing
with 691 additions and 1925 deletions
make clean
make
make build/max32665.bin
cp build/max32665.bin card10.bin
../bootloader/crc_patch.py card10.bin
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="ilg.gnuarmeclipse.debug.gdbjtag.openocd.launchConfigurationType">
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.doContinue" value="true"/>
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.doDebugInRam" value="false"/>
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.doFirstReset" value="true"/>
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.doGdbServerAllocateConsole" value="true"/>
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.doGdbServerAllocateTelnetConsole" value="false"/>
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.doSecondReset" value="true"/>
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.doStartGdbServer" value="true"/>
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.enableSemihosting" value="false"/>
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.firstResetType" value="init"/>
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.gdbClientOtherCommands" value=""/>
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.gdbClientOtherOptions" value=""/>
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.gdbServerConnectionAddress" value=""/>
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.gdbServerExecutable" value="openocd"/>
<intAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.gdbServerGdbPortNumber" value="3333"/>
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.gdbServerLog" value=""/>
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.gdbServerOther" value="-s ${env_var:TOOLCHAIN_PATH}/share/openocd/scripts -f interface/ftdi/olimex-arm-usb-tiny-h.cfg -f target/MAX32650.cfg"/>
<intAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.gdbServerTelnetPortNumber" value="4444"/>
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.otherInitCommands" value=""/>
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.otherRunCommands" value=""/>
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.secondResetType" value="halt"/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.imageFileName" value=""/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.imageOffset" value=""/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.ipAddress" value="localhost"/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.jtagDevice" value="GNU ARM OpenOCD"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.loadImage" value="true"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.loadSymbols" value="true"/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.pcRegister" value=""/>
<intAttribute key="org.eclipse.cdt.debug.gdbjtag.core.portNumber" value="3333"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setPcRegister" value="false"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setResume" value="false"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setStopAt" value="true"/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.stopAt" value="main"/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.symbolsFileName" value=""/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.symbolsOffset" value=""/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useFileForImage" value="false"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useFileForSymbols" value="false"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useProjBinaryForImage" value="true"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useProjBinaryForSymbols" value="true"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useRemoteTarget" value="true"/>
<stringAttribute key="org.eclipse.cdt.debug.mi.core.commandFactory" value="Standard (Windows)"/>
<stringAttribute key="org.eclipse.cdt.debug.mi.core.protocol" value="mi"/>
<booleanAttribute key="org.eclipse.cdt.debug.mi.core.verboseMode" value="false"/>
<stringAttribute key="org.eclipse.cdt.dsf.gdb.DEBUG_NAME" value="arm-none-eabi-gdb"/>
<booleanAttribute key="org.eclipse.cdt.dsf.gdb.UPDATE_THREADLIST_ON_SUSPEND" value="false"/>
<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="2"/>
<stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/>
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_REGISTER_GROUPS" value=""/>
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="build/fit.elf"/>
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="fit"/>
<booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="true"/>
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.1674944962"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/fit"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
</listAttribute>
<stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;memoryBlockExpressionList context=&quot;Context string&quot;/&gt;&#13;&#10;"/>
<stringAttribute key="process_factory_id" value="org.eclipse.cdt.dsf.gdb.GdbProcessFactory"/>
</launchConfiguration>
/*************************************************************************************************/
/*!
* \file
*
* \brief Fitness sample application for the following profiles:
* Heart Rate profile
*
* Copyright (c) 2011-2018 Arm Ltd. All Rights Reserved.
* ARM Ltd. confidential and proprietary.
*
* IMPORTANT. Your use of this file is governed by a Software License Agreement
* ("Agreement") that must be accepted in order to download or otherwise receive a
* copy of this file. You may not use or copy this file for any purpose other than
* as described in the Agreement. If you do not agree to all of the terms of the
* Agreement do not use this file and delete all copies in your possession or control;
* if you do not have a copy of the Agreement, you must contact ARM Ltd. prior
* to any use, copying or further distribution of this software.
*/
/*************************************************************************************************/
#include <string.h>
#include "wsf_types.h"
#include "util/bstream.h"
#include "wsf_msg.h"
#include "wsf_trace.h"
#include "hci_api.h"
#include "dm_api.h"
#include "att_api.h"
#include "smp_api.h"
#include "app_api.h"
#include "app_db.h"
#include "app_ui.h"
#include "app_hw.h"
#include "svc_ch.h"
#include "svc_core.h"
#include "svc_hrs.h"
#include "svc_dis.h"
#include "svc_batt.h"
#include "svc_rscs.h"
#include "bas/bas_api.h"
#include "hrps/hrps_api.h"
#include "rscp/rscp_api.h"
#include "fit_api.h"
/**************************************************************************************************
Macros
**************************************************************************************************/
/*! WSF message event starting value */
#define FIT_MSG_START 0xA0
/* Default Running Speed and Cadence Measurement period (seconds) */
#define FIT_DEFAULT_RSCM_PERIOD 1
/*! WSF message event enumeration */
enum
{
FIT_HR_TIMER_IND = FIT_MSG_START, /*! Heart rate measurement timer expired */
FIT_BATT_TIMER_IND, /*! Battery measurement timer expired */
FIT_RUNNING_TIMER_IND /*! Running speed and cadence measurement timer expired */
};
/**************************************************************************************************
Data Types
**************************************************************************************************/
/*! Application message type */
typedef union
{
wsfMsgHdr_t hdr;
dmEvt_t dm;
attsCccEvt_t ccc;
attEvt_t att;
} fitMsg_t;
/**************************************************************************************************
Configurable Parameters
**************************************************************************************************/
/*! configurable parameters for advertising */
/* These intervals directly impact energy usage during the non-connected/advertising mode */
static const appAdvCfg_t fitAdvCfg =
{
{ 1000, 0, 0}, /*! Advertising durations in ms */
{ 96, 200, 0} /*! Advertising intervals in 0.625 ms units */
};
/*! configurable parameters for slave */
static const appSlaveCfg_t fitSlaveCfg =
{
FIT_CONN_MAX, /*! Maximum connections */
};
/*! configurable parameters for security */
static const appSecCfg_t fitSecCfg =
{
DM_AUTH_BOND_FLAG | DM_AUTH_SC_FLAG, /*! Authentication and bonding flags */
0, /*! Initiator key distribution flags */
DM_KEY_DIST_LTK, /*! Responder key distribution flags */
FALSE, /*! TRUE if Out-of-band pairing data is present */
TRUE /*! TRUE to initiate security upon connection */
};
/*! configurable parameters for connection parameter update */
static const appUpdateCfg_t fitUpdateCfg =
{
6000, /*! Connection idle period in ms before attempting
connection parameter update; set to zero to disable */
640, /*! Minimum connection interval in 1.25ms units */
800, /*! Maximum connection interval in 1.25ms units */
0, /*! Connection latency */
900, /*! Supervision timeout in 10ms units */
5 /*! Number of update attempts before giving up */
};
/*! heart rate measurement configuration */
static const hrpsCfg_t fitHrpsCfg =
{
2000 /*! Measurement timer expiration period in ms */
};
/*! battery measurement configuration */
static const basCfg_t fitBasCfg =
{
30, /*! Battery measurement timer expiration period in seconds */
1, /*! Perform battery measurement after this many timer periods */
100 /*! Send battery level notification to peer when below this level. */
};
/*! SMP security parameter configuration */
static const smpCfg_t fitSmpCfg =
{
3000, /*! 'Repeated attempts' timeout in msec */
SMP_IO_NO_IN_NO_OUT, /*! I/O Capability */
7, /*! Minimum encryption key length */
16, /*! Maximum encryption key length */
3, /*! Attempts to trigger 'repeated attempts' timeout */
0, /*! Device authentication requirements */
};
/**************************************************************************************************
Advertising Data
**************************************************************************************************/
/*! advertising data, discoverable mode */
static const uint8_t fitAdvDataDisc[] =
{
/*! flags */
2, /*! length */
DM_ADV_TYPE_FLAGS, /*! AD type */
DM_FLAG_LE_GENERAL_DISC | /*! flags */
DM_FLAG_LE_BREDR_NOT_SUP,
/*! tx power */
2, /*! length */
DM_ADV_TYPE_TX_POWER, /*! AD type */
0, /*! tx power */
/*! service UUID list */
9, /*! length */
DM_ADV_TYPE_16_UUID, /*! AD type */
UINT16_TO_BYTES(ATT_UUID_HEART_RATE_SERVICE),
UINT16_TO_BYTES(ATT_UUID_RUNNING_SPEED_SERVICE),
UINT16_TO_BYTES(ATT_UUID_DEVICE_INFO_SERVICE),
UINT16_TO_BYTES(ATT_UUID_BATTERY_SERVICE)
};
/*! scan data, discoverable mode */
static const uint8_t fitScanDataDisc[] =
{
/*! device name */
4, /*! length */
DM_ADV_TYPE_LOCAL_NAME, /*! AD type */
'F',
'i',
't'
};
/**************************************************************************************************
Client Characteristic Configuration Descriptors
**************************************************************************************************/
/*! enumeration of client characteristic configuration descriptors */
enum
{
FIT_GATT_SC_CCC_IDX, /*! GATT service, service changed characteristic */
FIT_HRS_HRM_CCC_IDX, /*! Heart rate service, heart rate monitor characteristic */
FIT_BATT_LVL_CCC_IDX, /*! Battery service, battery level characteristic */
FIT_RSCS_SM_CCC_IDX, /*! Runninc speed and cadence measurement characteristic */
FIT_NUM_CCC_IDX
};
/*! client characteristic configuration descriptors settings, indexed by above enumeration */
static const attsCccSet_t fitCccSet[FIT_NUM_CCC_IDX] =
{
/* cccd handle value range security level */
{GATT_SC_CH_CCC_HDL, ATT_CLIENT_CFG_INDICATE, DM_SEC_LEVEL_NONE}, /* FIT_GATT_SC_CCC_IDX */
{HRS_HRM_CH_CCC_HDL, ATT_CLIENT_CFG_NOTIFY, DM_SEC_LEVEL_NONE}, /* FIT_HRS_HRM_CCC_IDX */
{BATT_LVL_CH_CCC_HDL, ATT_CLIENT_CFG_NOTIFY, DM_SEC_LEVEL_NONE}, /* FIT_BATT_LVL_CCC_IDX */
{RSCS_RSM_CH_CCC_HDL, ATT_CLIENT_CFG_NOTIFY, DM_SEC_LEVEL_NONE} /* FIT_RSCS_SM_CCC_IDX */
};
/**************************************************************************************************
Global Variables
**************************************************************************************************/
/*! WSF handler ID */
wsfHandlerId_t fitHandlerId;
/* WSF Timer to send running speed and cadence measurement data */
wsfTimer_t fitRscmTimer;
/* Running Speed and Cadence Measurement period - Can be changed at runtime to vary period */
static uint16_t fitRscmPeriod = FIT_DEFAULT_RSCM_PERIOD;
/* Heart Rate Monitor feature flags */
static uint8_t fitHrmFlags = CH_HRM_FLAGS_VALUE_8BIT | CH_HRM_FLAGS_ENERGY_EXP;
/*************************************************************************************************/
/*!
* \brief Application DM callback.
*
* \param pDmEvt DM callback event
*
* \return None.
*/
/*************************************************************************************************/
static void fitDmCback(dmEvt_t *pDmEvt)
{
dmEvt_t *pMsg;
uint16_t len;
len = DmSizeOfEvt(pDmEvt);
if ((pMsg = WsfMsgAlloc(len)) != NULL)
{
memcpy(pMsg, pDmEvt, len);
WsfMsgSend(fitHandlerId, pMsg);
}
}
/*************************************************************************************************/
/*!
* \brief Application ATT callback.
*
* \param pEvt ATT callback event
*
* \return None.
*/
/*************************************************************************************************/
static void fitAttCback(attEvt_t *pEvt)
{
attEvt_t *pMsg;
if ((pMsg = WsfMsgAlloc(sizeof(attEvt_t) + pEvt->valueLen)) != NULL)
{
memcpy(pMsg, pEvt, sizeof(attEvt_t));
pMsg->pValue = (uint8_t *) (pMsg + 1);
memcpy(pMsg->pValue, pEvt->pValue, pEvt->valueLen);
WsfMsgSend(fitHandlerId, pMsg);
}
}
/*************************************************************************************************/
/*!
* \brief Application ATTS client characteristic configuration callback.
*
* \param pDmEvt DM callback event
*
* \return None.
*/
/*************************************************************************************************/
static void fitCccCback(attsCccEvt_t *pEvt)
{
attsCccEvt_t *pMsg;
appDbHdl_t dbHdl;
/* if CCC not set from initialization and there's a device record */
if ((pEvt->handle != ATT_HANDLE_NONE) &&
((dbHdl = AppDbGetHdl((dmConnId_t) pEvt->hdr.param)) != APP_DB_HDL_NONE))
{
/* store value in device database */
AppDbSetCccTblValue(dbHdl, pEvt->idx, pEvt->value);
}
if ((pMsg = WsfMsgAlloc(sizeof(attsCccEvt_t))) != NULL)
{
memcpy(pMsg, pEvt, sizeof(attsCccEvt_t));
WsfMsgSend(fitHandlerId, pMsg);
}
}
/*************************************************************************************************/
/*!
* \brief Send a Running Speed and Cadence Measurement Notification.
*
* \param connId connection ID
*
* \return None.
*/
/*************************************************************************************************/
static void fitSendRunningSpeedMeasurement(dmConnId_t connId)
{
if (AttsCccEnabled(connId, FIT_RSCS_SM_CCC_IDX))
{
static uint8_t walk_run = 1;
/* TODO: Set Running Speed and Cadence Measurement Parameters */
RscpsSetParameter(RSCP_SM_PARAM_SPEED, 1);
RscpsSetParameter(RSCP_SM_PARAM_CADENCE, 2);
RscpsSetParameter(RSCP_SM_PARAM_STRIDE_LENGTH, 3);
RscpsSetParameter(RSCP_SM_PARAM_TOTAL_DISTANCE, 4);
/* Toggle running/walking */
walk_run = walk_run? 0 : 1;
RscpsSetParameter(RSCP_SM_PARAM_STATUS, walk_run);
RscpsSendSpeedMeasurement(connId);
}
/* Configure and start timer to send the next measurement */
fitRscmTimer.msg.event = FIT_RUNNING_TIMER_IND;
fitRscmTimer.msg.status = FIT_RSCS_SM_CCC_IDX;
fitRscmTimer.handlerId = fitHandlerId;
fitRscmTimer.msg.param = connId;
WsfTimerStartSec(&fitRscmTimer, fitRscmPeriod);
}
/*************************************************************************************************/
/*!
* \brief Process CCC state change.
*
* \param pMsg Pointer to message.
*
* \return None.
*/
/*************************************************************************************************/
static void fitProcCccState(fitMsg_t *pMsg)
{
APP_TRACE_INFO3("ccc state ind value:%d handle:%d idx:%d", pMsg->ccc.value, pMsg->ccc.handle, pMsg->ccc.idx);
/* handle heart rate measurement CCC */
if (pMsg->ccc.idx == FIT_HRS_HRM_CCC_IDX)
{
if (pMsg->ccc.value == ATT_CLIENT_CFG_NOTIFY)
{
HrpsMeasStart((dmConnId_t) pMsg->ccc.hdr.param, FIT_HR_TIMER_IND, FIT_HRS_HRM_CCC_IDX);
}
else
{
HrpsMeasStop((dmConnId_t) pMsg->ccc.hdr.param);
}
return;
}
/* handle running speed and cadence measurement CCC */
if (pMsg->ccc.idx == FIT_RSCS_SM_CCC_IDX)
{
if (pMsg->ccc.value == ATT_CLIENT_CFG_NOTIFY)
{
fitSendRunningSpeedMeasurement((dmConnId_t)pMsg->ccc.hdr.param);
}
else
{
WsfTimerStop(&fitRscmTimer);
}
return;
}
/* handle battery level CCC */
if (pMsg->ccc.idx == FIT_BATT_LVL_CCC_IDX)
{
if (pMsg->ccc.value == ATT_CLIENT_CFG_NOTIFY)
{
BasMeasBattStart((dmConnId_t) pMsg->ccc.hdr.param, FIT_BATT_TIMER_IND, FIT_BATT_LVL_CCC_IDX);
}
else
{
BasMeasBattStop((dmConnId_t) pMsg->ccc.hdr.param);
}
return;
}
}
/*************************************************************************************************/
/*!
* \brief Perform UI actions on connection close.
*
* \param pMsg Pointer to message.
*
* \return None.
*/
/*************************************************************************************************/
static void fitClose(fitMsg_t *pMsg)
{
/* stop heart rate measurement */
HrpsMeasStop((dmConnId_t) pMsg->hdr.param);
/* stop battery measurement */
BasMeasBattStop((dmConnId_t) pMsg->hdr.param);
/* Stop running speed and cadence timer */
WsfTimerStop(&fitRscmTimer);
}
/*************************************************************************************************/
/*!
* \brief Set up advertising and other procedures that need to be performed after
* device reset.
*
* \param pMsg Pointer to message.
*
* \return None.
*/
/*************************************************************************************************/
static void fitSetup(fitMsg_t *pMsg)
{
/* set advertising and scan response data for discoverable mode */
AppAdvSetData(APP_ADV_DATA_DISCOVERABLE, sizeof(fitAdvDataDisc), (uint8_t *) fitAdvDataDisc);
AppAdvSetData(APP_SCAN_DATA_DISCOVERABLE, sizeof(fitScanDataDisc), (uint8_t *) fitScanDataDisc);
/* set advertising and scan response data for connectable mode */
AppAdvSetData(APP_ADV_DATA_CONNECTABLE, 0, NULL);
AppAdvSetData(APP_SCAN_DATA_CONNECTABLE, 0, NULL);
/* start advertising; automatically set connectable/discoverable mode and bondable mode */
AppAdvStart(APP_MODE_AUTO_INIT);
}
/*************************************************************************************************/
/*!
* \brief Button press callback.
*
* \param btn Button press.
*
* \return None.
*/
/*************************************************************************************************/
static void fitBtnCback(uint8_t btn)
{
dmConnId_t connId;
static uint8_t heartRate = 78; /* for testing/demonstration */
/* button actions when connected */
if ((connId = AppConnIsOpen()) != DM_CONN_ID_NONE)
{
switch (btn)
{
case APP_UI_BTN_1_SHORT:
/* increment the heart rate */
AppHwHrmTest(++heartRate);
break;
case APP_UI_BTN_1_MED:
break;
case APP_UI_BTN_1_LONG:
AppConnClose(connId);
break;
case APP_UI_BTN_2_SHORT:
/* decrement the heart rate */
AppHwHrmTest(--heartRate);
break;
case APP_UI_BTN_2_MED:
/* Toggle HRM Sensor DET flags */
if (!(fitHrmFlags & (CH_HRM_FLAGS_SENSOR_DET | CH_HRM_FLAGS_SENSOR_NOT_DET)))
{
fitHrmFlags |= CH_HRM_FLAGS_SENSOR_DET;
}
else if (fitHrmFlags & CH_HRM_FLAGS_SENSOR_DET)
{
fitHrmFlags &= ~CH_HRM_FLAGS_SENSOR_DET;
fitHrmFlags |= CH_HRM_FLAGS_SENSOR_NOT_DET;
}
else
{
fitHrmFlags &= ~CH_HRM_FLAGS_SENSOR_NOT_DET;
}
HrpsSetFlags(fitHrmFlags);
break;
case APP_UI_BTN_2_LONG:
/* Toggle HRM RR Interval feature flag */
if (fitHrmFlags & CH_HRM_FLAGS_RR_INTERVAL)
{
fitHrmFlags &= ~CH_HRM_FLAGS_RR_INTERVAL;
}
else
{
fitHrmFlags |= CH_HRM_FLAGS_RR_INTERVAL;
}
HrpsSetFlags(fitHrmFlags);
break;
default:
break;
}
}
/* button actions when not connected */
else
{
switch (btn)
{
case APP_UI_BTN_1_SHORT:
/* start or restart advertising */
AppAdvStart(APP_MODE_AUTO_INIT);
break;
case APP_UI_BTN_1_MED:
/* enter discoverable and bondable mode mode */
AppSetBondable(TRUE);
AppAdvStart(APP_MODE_DISCOVERABLE);
break;
case APP_UI_BTN_1_LONG:
/* clear bonded device info and restart advertising */
AppDbDeleteAllRecords();
AppAdvStart(APP_MODE_AUTO_INIT);
break;
case APP_UI_BTN_2_SHORT:
/* Toggle HRM Flag for 8 and 16 bit values */
if (fitHrmFlags & CH_HRM_FLAGS_VALUE_16BIT)
{
fitHrmFlags &= ~CH_HRM_FLAGS_VALUE_16BIT;
}
else
{
fitHrmFlags |= CH_HRM_FLAGS_VALUE_16BIT;
}
HrpsSetFlags(fitHrmFlags);
break;
default:
break;
}
}
}
/*************************************************************************************************/
/*!
* \brief Process messages from the event handler.
*
* \param pMsg Pointer to message.
*
* \return None.
*/
/*************************************************************************************************/
static void fitProcMsg(fitMsg_t *pMsg)
{
uint8_t uiEvent = APP_UI_NONE;
switch(pMsg->hdr.event)
{
case FIT_RUNNING_TIMER_IND:
fitSendRunningSpeedMeasurement((dmConnId_t)pMsg->ccc.hdr.param);
break;
case FIT_HR_TIMER_IND:
HrpsProcMsg(&pMsg->hdr);
break;
case FIT_BATT_TIMER_IND:
BasProcMsg(&pMsg->hdr);
break;
case ATTS_HANDLE_VALUE_CNF:
HrpsProcMsg(&pMsg->hdr);
BasProcMsg(&pMsg->hdr);
break;
case ATTS_CCC_STATE_IND:
fitProcCccState(pMsg);
break;
case DM_RESET_CMPL_IND:
DmSecGenerateEccKeyReq();
fitSetup(pMsg);
uiEvent = APP_UI_RESET_CMPL;
break;
case DM_ADV_START_IND:
uiEvent = APP_UI_ADV_START;
break;
case DM_ADV_STOP_IND:
uiEvent = APP_UI_ADV_STOP;
break;
case DM_CONN_OPEN_IND:
HrpsProcMsg(&pMsg->hdr);
BasProcMsg(&pMsg->hdr);
uiEvent = APP_UI_CONN_OPEN;
break;
case DM_CONN_CLOSE_IND:
fitClose(pMsg);
uiEvent = APP_UI_CONN_CLOSE;
break;
case DM_SEC_PAIR_CMPL_IND:
uiEvent = APP_UI_SEC_PAIR_CMPL;
break;
case DM_SEC_PAIR_FAIL_IND:
uiEvent = APP_UI_SEC_PAIR_FAIL;
break;
case DM_SEC_ENCRYPT_IND:
uiEvent = APP_UI_SEC_ENCRYPT;
break;
case DM_SEC_ENCRYPT_FAIL_IND:
uiEvent = APP_UI_SEC_ENCRYPT_FAIL;
break;
case DM_SEC_AUTH_REQ_IND:
AppHandlePasskey(&pMsg->dm.authReq);
break;
case DM_SEC_ECC_KEY_IND:
DmSecSetEccKey(&pMsg->dm.eccMsg.data.key);
break;
case DM_SEC_COMPARE_IND:
AppHandleNumericComparison(&pMsg->dm.cnfInd);
break;
case DM_HW_ERROR_IND:
uiEvent = APP_UI_HW_ERROR;
break;
default:
break;
}
if (uiEvent != APP_UI_NONE)
{
AppUiAction(uiEvent);
}
}
/*************************************************************************************************/
/*!
* \brief Application handler init function called during system initialization.
*
* \param handlerID WSF handler ID.
*
* \return None.
*/
/*************************************************************************************************/
void FitHandlerInit(wsfHandlerId_t handlerId)
{
APP_TRACE_INFO0("FitHandlerInit");
/* store handler ID */
fitHandlerId = handlerId;
/* Set configuration pointers */
pAppAdvCfg = (appAdvCfg_t *) &fitAdvCfg;
pAppSlaveCfg = (appSlaveCfg_t *) &fitSlaveCfg;
pAppSecCfg = (appSecCfg_t *) &fitSecCfg;
pAppUpdateCfg = (appUpdateCfg_t *) &fitUpdateCfg;
/* Initialize application framework */
AppSlaveInit();
/* Set stack configuration pointers */
pSmpCfg = (smpCfg_t *) &fitSmpCfg;
/* initialize heart rate profile sensor */
HrpsInit(handlerId, (hrpsCfg_t *) &fitHrpsCfg);
HrpsSetFlags(fitHrmFlags);
/* initialize battery service server */
BasInit(handlerId, (basCfg_t *) &fitBasCfg);
}
/*************************************************************************************************/
/*!
* \brief WSF event handler for application.
*
* \param event WSF event mask.
* \param pMsg WSF message.
*
* \return None.
*/
/*************************************************************************************************/
void FitHandler(wsfEventMask_t event, wsfMsgHdr_t *pMsg)
{
if (pMsg != NULL)
{
APP_TRACE_INFO1("Fit got evt %d", pMsg->event);
if (pMsg->event >= DM_CBACK_START && pMsg->event <= DM_CBACK_END)
{
/* process advertising and connection-related messages */
AppSlaveProcDmMsg((dmEvt_t *) pMsg);
/* process security-related messages */
AppSlaveSecProcDmMsg((dmEvt_t *) pMsg);
}
/* perform profile and user interface-related operations */
fitProcMsg((fitMsg_t *) pMsg);
}
}
/*************************************************************************************************/
/*!
* \brief Start the application.
*
* \return None.
*/
/*************************************************************************************************/
void FitStart(void)
{
/* Register for stack callbacks */
DmRegister(fitDmCback);
DmConnRegister(DM_CLIENT_ID_APP, fitDmCback);
AttRegister(fitAttCback);
AttConnRegister(AppServerConnCback);
AttsCccRegister(FIT_NUM_CCC_IDX, (attsCccSet_t *) fitCccSet, fitCccCback);
/* Register for app framework callbacks */
AppUiBtnRegister(fitBtnCback);
/* Initialize attribute server database */
SvcCoreAddGroup();
SvcHrsCbackRegister(NULL, HrpsWriteCback);
SvcHrsAddGroup();
SvcDisAddGroup();
SvcBattCbackRegister(BasReadCback, NULL);
SvcBattAddGroup();
SvcRscsAddGroup();
/* Set running speed and cadence features */
RscpsSetFeatures(RSCS_ALL_FEATURES);
/* Reset the device */
DmDevReset();
}
/*******************************************************************************
* Copyright (C) 2018 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2019-02-11 23:36:35 +0000 (Mon, 11 Feb 2019) $
* $Revision: 40967 $
*
******************************************************************************/
#include <stdio.h>
#include <string.h>
#include "wsf_types.h"
#include "wsf_os.h"
#include "wsf_buf.h"
#include "wsf_timer.h"
#include "wsf_trace.h"
#include "app_ui.h"
#include "ll_api.h"
#include "sch_api.h"
#include "fit/fit_api.h"
#include "mxc_config.h"
#include "gcr_regs.h"
#include "mcr_regs.h"
#include "hci_core.h"
/**************************************************************************************************
Macros
**************************************************************************************************/
/* Number of WSF buffer pools */
#define WSF_BUF_POOLS 6
/* Size of buffer for stdio functions */
#define PRINTF_BUF_SIZE 128
/**************************************************************************************************
Local Variables
**************************************************************************************************/
/*! Buffer for stdio functions */
char printf_buffer[PRINTF_BUF_SIZE];
/*! Free memory for pool buffers (use word elements for word alignment). */
static uint32_t mainBufMem[3584/sizeof(uint32_t)+96];
/*! Default pool descriptor. */
static wsfBufPoolDesc_t mainPoolDesc[WSF_BUF_POOLS] =
{
{ 16, 8 },
{ 32, 4 },
{ 64, 4 },
{ 128, 4 },
{ 256, 4 },
{ 384, 4 }
};
/**************************************************************************************************
Functions
**************************************************************************************************/
/*! \brief Stack initialization for app. */
extern void StackInitFit(void);
void HciVsSetPublicAddr(uint8_t *bdAddr);
/*************************************************************************************************/
void SysTick_Handler(void)
{
WsfTimerUpdate(1);
}
/*************************************************************************************************/
static void myTrace(const char *pStr, va_list args)
{
extern uint8_t wsfCsNesting;
if (wsfCsNesting == 0)
{
vprintf(pStr, args);
printf("\r\n");
}
}
/*************************************************************************************************/
/*!
* \brief Initialize WSF.
*
* \return None.
*/
/*************************************************************************************************/
static void WsfInit(void)
{
WsfTimerInit();
WsfBufInit(sizeof(mainBufMem), (uint8_t*)mainBufMem, WSF_BUF_POOLS, mainPoolDesc);
WsfTraceRegister(myTrace);
}
/*************************************************************************************************/
/*!
* \brief Initialize platform.
*
* \param msPerTick Milliseconds per timer tick.
*
* \return None.
*/
/*************************************************************************************************/
void PlatformInit(void)
{
/* Change the pullup on the RST pin to 25K */
MXC_MCR->ctrl = 0x202;
/* Set VREGO_D to 1.3V */
*((volatile uint32_t*)0x40004410) = 0x50;
/* Set TX LDO to 1.1V and enable LDO. Set RX LDO to 0.9V and enable LDO */
MXC_GCR->btleldocn = 0xD9; // TX 1.1V RX 0.9V
/* Power up the 32MHz XO */
MXC_GCR->clkcn |= MXC_F_GCR_CLKCN_X32M_EN;
/* Enable peripheral clocks */
MXC_GCR->perckcn0 &= ~(MXC_F_GCR_PERCKCN0_GPIO0D | MXC_F_GCR_PERCKCN0_GPIO1D); // Clear GPIO0 and GPIO1 Disable
MXC_GCR->perckcn1 &= ~(MXC_F_GCR_PERCKCN1_BTLED | MXC_F_GCR_PERCKCN1_TRNGD ); // Clear BTLE and ICACHE0 disable
/* setup the systick */
SysTick->LOAD = (SystemCoreClock / 1000) * WSF_MS_PER_TICK;
SysTick->VAL = 0;
SysTick->CTRL |= (SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk | SysTick_CTRL_TICKINT_Msk);
#ifndef __IAR_SYSTEMS_ICC__
/* Added to prevent printf() and friends from using malloc() */
setvbuf(stdout, printf_buffer, _IOLBF, PRINTF_BUF_SIZE);
#endif
}
/*
* In two-chip solutions, setting the address must wait until the HCI interface is initialized.
* This handler can also catch other Application events, but none are currently implemented.
* See ble-profiles/sources/apps/app/common/app_ui.c for further details.
*
*/
void SetAddress(uint8_t event)
{
uint8_t bdAddr[6] = {0x02, 0x02, 0x44, 0x8B, 0x05, 0x00};
switch (event) {
case APP_UI_RESET_CMPL:
printf("Setting address -- MAC %02X:%02X:%02X:%02X:%02X:%02X\n", bdAddr[5], bdAddr[4], bdAddr[3], bdAddr[2], bdAddr[1], bdAddr[0]);
LlSetBdAddr((uint8_t*)&bdAddr);
LlGetBdAddr(hciCoreCb.bdAddr);
break;
default:
break;
}
}
/*************************************************************************************************/
/*!
* \brief Initialize MAC layer.
*
* \param None.
*
* \return None.
*/
/*************************************************************************************************/
extern int8_t tx_rfpower_on;
void MacInit(void)
{
wsfHandlerId_t handlerId;
/* Initialize link layer. */
BbInit();
handlerId = WsfOsSetNextHandler(SchHandler);
SchInit(handlerId);
LlAdvSlaveInit();
LlConnSlaveInit();
handlerId = WsfOsSetNextHandler(LlHandler);
LlHandlerInit(handlerId);
}
/*************************************************************************************************/
/*!
* \fn main
*
* \brief Entry point for demo software.
*
* \param None.
*
* \return None.
*/
/*************************************************************************************************/
int main(void)
{
printf("\n\n***** MAX32665 BLE Fitness Profile *****\n");
PlatformInit();
WsfInit();
MacInit();
StackInitFit();
FitStart();
printf("tx_rfpower_on = %d\n", tx_rfpower_on);
HciVsSetTxPower(-20);
//HciVsSetTxPower(-30);
//tx_rfpower_on = 10;
//LlSetTxPower(10);
printf("tx_rfpower_on = %d\n", tx_rfpower_on);
/* Register a handler for Application events */
AppUiActionRegister(SetAddress);
printf("Setup Complete\n");
while (1)
{
wsfOsDispatcher();
}
}
/*************************************************************************************************/
/*!
* \file
*
* \brief Stack initialization for fit.
*
* Copyright (c) 2016-2017 ARM Ltd. All Rights Reserved.
* ARM Ltd. confidential and proprietary.
*
* IMPORTANT. Your use of this file is governed by a Software License Agreement
* ("Agreement") that must be accepted in order to download or otherwise receive a
* copy of this file. You may not use or copy this file for any purpose other than
* as described in the Agreement. If you do not agree to all of the terms of the
* Agreement do not use this file and delete all copies in your possession or control;
* if you do not have a copy of the Agreement, you must contact ARM Ltd. prior
* to any use, copying or further distribution of this software.
*/
/*************************************************************************************************/
#include "wsf_types.h"
#include "wsf_os.h"
#include "util/bstream.h"
#include "fit/fit_api.h"
#include "hci_handler.h"
#include "dm_handler.h"
#include "l2c_handler.h"
#include "att_handler.h"
#include "smp_handler.h"
#include "l2c_api.h"
#include "att_api.h"
#include "smp_api.h"
#include "app_api.h"
#include "svc_dis.h"
#include "svc_core.h"
#include "sec_api.h"
/*************************************************************************************************/
/*!
* \brief Initialize stack.
*
* \return None.
*/
/*************************************************************************************************/
void StackInitFit(void)
{
wsfHandlerId_t handlerId;
uint8_t features[sizeof(uint64_t)];
uint8_t mask[sizeof(uint64_t)];
SecInit();
SecAesInit();
SecCmacInit();
SecEccInit();
// Only use legacy API.
Uint64ToBstream(features, 0);
Uint64ToBstream(mask, HCI_LE_SUP_FEAT_LE_EXT_ADV);
HciVsSetFeatures(features, mask);
handlerId = WsfOsSetNextHandler(HciHandler);
HciHandlerInit(handlerId);
handlerId = WsfOsSetNextHandler(DmHandler);
DmDevVsInit(0);
DmAdvInit();
DmConnInit();
DmConnSlaveInit();
DmSecInit();
DmSecLescInit();
DmPrivInit();
DmHandlerInit(handlerId);
handlerId = WsfOsSetNextHandler(L2cSlaveHandler);
L2cSlaveHandlerInit(handlerId);
L2cInit();
L2cSlaveInit();
handlerId = WsfOsSetNextHandler(AttHandler);
AttHandlerInit(handlerId);
AttsInit();
AttsIndInit();
handlerId = WsfOsSetNextHandler(SmpHandler);
SmpHandlerInit(handlerId);
SmprInit();
SmprScInit();
HciSetMaxRxAclLen(100);
handlerId = WsfOsSetNextHandler(AppHandler);
AppHandlerInit(handlerId);
handlerId = WsfOsSetNextHandler(FitHandler);
FitHandlerInit(handlerId);
}
/*************************************************************************************************/
/*!
* \file svc_dis.c
*
* \brief Example Device Information Service implementation.
*
* $Date: 2018-04-17 23:02:20 +0000 (Tue, 17 Apr 2018) $
* $Revision: 34673 $
*
* Copyright (c) 2011 Wicentric, Inc., all rights reserved.
* Wicentric confidential and proprietary.
*
* IMPORTANT. Your use of this file is governed by a Software License Agreement
* ("Agreement") that must be accepted in order to download or otherwise receive a
* copy of this file. You may not use or copy this file for any purpose other than
* as described in the Agreement. If you do not agree to all of the terms of the
* Agreement do not use this file and delete all copies in your possession or control;
* if you do not have a copy of the Agreement, you must contact Wicentric, Inc. prior
* to any use, copying or further distribution of this software.
*/
/*************************************************************************************************/
#include "wsf_types.h"
#include "att_api.h"
#include "wsf_trace.h"
#include "util/bstream.h"
#include "svc_dis.h"
#include "svc_cfg.h"
/**************************************************************************************************
Macros
**************************************************************************************************/
/*! Characteristic read permissions */
#ifndef DIS_SEC_PERMIT_READ
#define DIS_SEC_PERMIT_READ SVC_SEC_PERMIT_READ
#endif
/**************************************************************************************************
Service variables
**************************************************************************************************/
/* Device information service declaration */
static const uint8_t disValSvc[] = {UINT16_TO_BYTES(ATT_UUID_DEVICE_INFO_SERVICE)};
static const uint16_t disLenSvc = sizeof(disValSvc);
/* Manufacturer name string characteristic */
static const uint8_t disValMfrCh[] = {ATT_PROP_READ, UINT16_TO_BYTES(DIS_MFR_HDL), UINT16_TO_BYTES(ATT_UUID_MANUFACTURER_NAME)};
static const uint16_t disLenMfrCh = sizeof(disValMfrCh);
/* Manufacturer name string */
static const uint8_t disUuMfr[] = {UINT16_TO_BYTES(ATT_UUID_MANUFACTURER_NAME)};
static const uint8_t disValMfr[] = "Maxim Integrated";
static const uint16_t disLenMfr = sizeof(disValMfr) - 1;
/* System ID characteristic */
static const uint8_t disValSidCh[] = {ATT_PROP_READ, UINT16_TO_BYTES(DIS_SID_HDL), UINT16_TO_BYTES(ATT_UUID_SYSTEM_ID)};
static const uint16_t disLenSidCh = sizeof(disValSidCh);
/* System ID */
static const uint8_t disUuSid[] = {UINT16_TO_BYTES(ATT_UUID_SYSTEM_ID)};
static uint8_t disValSid[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
static const uint16_t disLenSid = sizeof(disValSid);
/* Model number string characteristic */
static const uint8_t disValMnCh[] = {ATT_PROP_READ, UINT16_TO_BYTES(DIS_MN_HDL), UINT16_TO_BYTES(ATT_UUID_MODEL_NUMBER)};
static const uint16_t disLenMnCh = sizeof(disValMnCh);
/* Model number string */
static const uint8_t disUuMn[] = {UINT16_TO_BYTES(ATT_UUID_MODEL_NUMBER)};
static const uint8_t disValMn[] = "MAX32565";
static const uint16_t disLenMn = sizeof(disValMn) - 1;
/* Serial number string characteristic */
static const uint8_t disValSnCh[] = {ATT_PROP_READ, UINT16_TO_BYTES(DIS_SN_HDL), UINT16_TO_BYTES(ATT_UUID_SERIAL_NUMBER)};
static const uint16_t disLenSnCh = sizeof(disValSnCh);
/* Serial number string */
static const uint8_t disUuSn[] = {UINT16_TO_BYTES(ATT_UUID_SERIAL_NUMBER)};
static const uint8_t disValSn[] = "serial num";
static const uint16_t disLenSn = sizeof(disValSn) - 1;
/* Firmware revision string characteristic */
static const uint8_t disValFwrCh[] = {ATT_PROP_READ, UINT16_TO_BYTES(DIS_FWR_HDL), UINT16_TO_BYTES(ATT_UUID_FIRMWARE_REV)};
static const uint16_t disLenFwrCh = sizeof(disValFwrCh);
/* Firmware revision string */
static const uint8_t disUuFwr[] = {UINT16_TO_BYTES(ATT_UUID_FIRMWARE_REV)};
static const uint8_t disValFwr[] = "fw rev";
static const uint16_t disLenFwr = sizeof(disValFwr) - 1;
/* Hardware revision string characteristic */
static const uint8_t disValHwrCh[] = {ATT_PROP_READ, UINT16_TO_BYTES(DIS_HWR_HDL), UINT16_TO_BYTES(ATT_UUID_HARDWARE_REV)};
static const uint16_t disLenHwrCh = sizeof(disValHwrCh);
/* Hardware revision string */
static const uint8_t disUuHwr[] = {UINT16_TO_BYTES(ATT_UUID_HARDWARE_REV)};
static const uint8_t disValHwr[] = "hw rev";
static const uint16_t disLenHwr = sizeof(disValHwr) - 1;
/* Software revision string characteristic */
static const uint8_t disValSwrCh[] = {ATT_PROP_READ, UINT16_TO_BYTES(DIS_SWR_HDL), UINT16_TO_BYTES(ATT_UUID_SOFTWARE_REV)};
static const uint16_t disLenSwrCh = sizeof(disValSwrCh);
/* Software revision string */
static const uint8_t disUuSwr[] = {UINT16_TO_BYTES(ATT_UUID_SOFTWARE_REV)};
static const uint8_t disValSwr[] = "sw rev";
static const uint16_t disLenSwr = sizeof(disValSwr) - 1;
/* Registration certificate data characteristic */
static const uint8_t disValRcdCh[] = {ATT_PROP_READ, UINT16_TO_BYTES(DIS_RCD_HDL), UINT16_TO_BYTES(ATT_UUID_11073_CERT_DATA)};
static const uint16_t disLenRcdCh = sizeof(disValRcdCh);
/* Registration certificate data */
static const uint8_t disUuRcd[] = {UINT16_TO_BYTES(ATT_UUID_11073_CERT_DATA)};
static const uint8_t disValRcd[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static const uint16_t disLenRcd = sizeof(disValRcd);
/* Attribute list for dis group */
static const attsAttr_t disList[] =
{
{
attPrimSvcUuid,
(uint8_t *) disValSvc,
(uint16_t *) &disLenSvc,
sizeof(disValSvc),
0,
ATTS_PERMIT_READ
},
{
attChUuid,
(uint8_t *) disValMfrCh,
(uint16_t *) &disLenMfrCh,
sizeof(disValMfrCh),
0,
ATTS_PERMIT_READ
},
{
disUuMfr,
(uint8_t *) disValMfr,
(uint16_t *) &disLenMfr,
sizeof(disValMfr) - 1,
0,
DIS_SEC_PERMIT_READ
},
{
attChUuid,
(uint8_t *) disValSidCh,
(uint16_t *) &disLenSidCh,
sizeof(disValSidCh),
0,
ATTS_PERMIT_READ
},
{
disUuSid,
disValSid,
(uint16_t *) &disLenSid,
sizeof(disValSid),
0,
DIS_SEC_PERMIT_READ
},
{
attChUuid,
(uint8_t *) disValMnCh,
(uint16_t *) &disLenMnCh,
sizeof(disValMnCh),
0,
ATTS_PERMIT_READ
},
{
disUuMn,
(uint8_t *) disValMn,
(uint16_t *) &disLenMn,
sizeof(disValMn) - 1,
0,
DIS_SEC_PERMIT_READ
},
{
attChUuid,
(uint8_t *) disValSnCh,
(uint16_t *) &disLenSnCh,
sizeof(disValSnCh),
0,
ATTS_PERMIT_READ
},
{
disUuSn,
(uint8_t *) disValSn,
(uint16_t *) &disLenSn,
sizeof(disValSn) - 1,
0,
DIS_SEC_PERMIT_READ
},
{
attChUuid,
(uint8_t *) disValFwrCh,
(uint16_t *) &disLenFwrCh,
sizeof(disValFwrCh),
0,
ATTS_PERMIT_READ
},
{
disUuFwr,
(uint8_t *) disValFwr,
(uint16_t *) &disLenFwr,
sizeof(disValFwr) - 1,
0,
DIS_SEC_PERMIT_READ
},
{
attChUuid,
(uint8_t *) disValHwrCh,
(uint16_t *) &disLenHwrCh,
sizeof(disValHwrCh),
0,
ATTS_PERMIT_READ
},
{
disUuHwr,
(uint8_t *) disValHwr,
(uint16_t *) &disLenHwr,
sizeof(disValHwr) - 1,
0,
DIS_SEC_PERMIT_READ
},
{
attChUuid,
(uint8_t *) disValSwrCh,
(uint16_t *) &disLenSwrCh,
sizeof(disValSwrCh),
0,
ATTS_PERMIT_READ
},
{
disUuSwr,
(uint8_t *) disValSwr,
(uint16_t *) &disLenSwr,
sizeof(disValSwr) - 1,
0,
DIS_SEC_PERMIT_READ
},
{
attChUuid,
(uint8_t *) disValRcdCh,
(uint16_t *) &disLenRcdCh,
sizeof(disValRcdCh),
0,
ATTS_PERMIT_READ
},
{
disUuRcd,
(uint8_t *) disValRcd,
(uint16_t *) &disLenRcd,
sizeof(disValRcd),
0,
DIS_SEC_PERMIT_READ
},
};
/* DIS group structure */
static attsGroup_t svcDisGroup =
{
NULL,
(attsAttr_t *) disList,
NULL,
NULL,
DIS_START_HDL,
DIS_END_HDL
};
/*************************************************************************************************/
/*!
* \fn SvcDisAddGroup
*
* \brief Add the services to the attribute server.
*
* \return None.
*/
/*************************************************************************************************/
void SvcDisAddGroup(void)
{
AttsAddGroup(&svcDisGroup);
}
/*************************************************************************************************/
/*!
* \fn SvcDisRemoveGroup
*
* \brief Remove the services from the attribute server.
*
* \return None.
*/
/*************************************************************************************************/
void SvcDisRemoveGroup(void)
{
AttsRemoveGroup(DIS_START_HDL);
}
source ../.gdbinit
file ../build/bootloader/bootloader.elf
#include "bootloader.h"
/* Autogenerated */
#include "splash-screen.h"
#include "card10-version.h"
#include "gfx.h"
#include "display.h"
static void bootloader_display_splash(void)
{
gfx_copy_region_rle_mono(
&display_screen,
0,
0,
160,
80,
sizeof(splash),
(const void *)(splash)
);
gfx_update(&display_screen);
}
/*
* Initialize the display.
*/
void bootloader_display_init(void)
{
bootloader_display_splash();
}
/*
* Show the bootloader version on the display.
*/
void bootloader_display_header(void)
{
gfx_clear(&display_screen);
Color white = gfx_color(&display_screen, WHITE);
bootloader_display_line(0, "Bootloader", white);
bootloader_display_line(1, __DATE__, white);
bootloader_display_line(2, CARD10_VERSION, white);
}
void bootloader_display_error(char *errtype, char *line1, char *line2)
{
gfx_clear(&display_screen);
Color red = gfx_color(&display_screen, RED);
Color yellow = gfx_color(&display_screen, YELLOW);
Color white = gfx_color(&display_screen, WHITE);
bootloader_display_line(0, "[FATAL ERROR]", red);
bootloader_display_line(1, errtype, yellow);
bootloader_display_line(2, CARD10_VERSION, white);
bootloader_display_line(3, line1, white);
bootloader_display_line(4, line2, white);
}
/*
* Display a line of text on the display.
*/
void bootloader_display_line(int line, char *string, uint16_t color)
{
Color black = gfx_color(&display_screen, BLACK);
gfx_puts(&Font16, &display_screen, 0, 16 * line, string, color, black);
gfx_update(&display_screen);
}
......@@ -38,24 +38,28 @@
* @brief USB Mass Storage Class
*/
#include <stdio.h>
#include <stddef.h>
#include "bootloader.h"
#include "descriptors.h"
#include "card10.h"
#include "led.h"
#include "mxc_config.h"
#include "mxc_sys.h"
#include "mxc_delay.h"
#include "board.h"
#include "led.h"
#include "usb.h"
#include "usb_event.h"
#include "enumerate.h"
#include "msc.h"
#include "descriptors.h"
#include "mscmem.h"
#include "card10.h"
#include <stdio.h>
#include <stddef.h>
/***** Definitions *****/
#define EVENT_ENUM_COMP MAXUSB_NUM_EVENTS
#define EVENT_REMOTE_WAKE (EVENT_ENUM_COMP + 1)
#define EVENT_ENUM_COMP MAXUSB_NUM_EVENTS
#define EVENT_REMOTE_WAKE (EVENT_ENUM_COMP + 1)
/***** Global Data *****/
volatile int configured;
......@@ -75,252 +79,271 @@ static void usb_app_wakeup(void);
/* This EP assignment must match the Configuration Descriptor */
static const msc_cfg_t msc_cfg = {
1, /* EP OUT */
MXC_USBHS_MAX_PACKET, /* OUT max packet size */
2, /* EP IN */
MXC_USBHS_MAX_PACKET, /* IN max packet size */
1, /* EP OUT */
MXC_USBHS_MAX_PACKET, /* OUT max packet size */
2, /* EP IN */
MXC_USBHS_MAX_PACKET, /* IN max packet size */
};
static const msc_idstrings_t ids = {
"MAXIM", /* Vendor string. Maximum of 8 bytes */
"MSC Example", /* Product string. Maximum of 16 bytes */
"1.0" /* Version string. Maximum of 4 bytes */
"CCC", /* Vendor string. Maximum of 8 bytes */
"card10", /* Product string. Maximum of 16 bytes */
"1.0" /* Version string. Maximum of 4 bytes */
};
/* Functions to control "disk" memory. See msc.h for definitions. */
static const msc_mem_t mem = {
mscmem_init,
mscmem_start,
mscmem_stop,
mscmem_ready,
mscmem_size,
mscmem_read,
mscmem_write,
mscmem_init, mscmem_start, mscmem_stop, mscmem_ready,
mscmem_size, mscmem_read, mscmem_write,
};
/* This callback is used to allow the driver to call part specific initialization functions. */
int usb_startup_cb()
{
const sys_cfg_usbhs_t sys_usbhs_cfg = NULL;
return SYS_USBHS_Init(&sys_usbhs_cfg);
const sys_cfg_usbhs_t sys_usbhs_cfg = NULL;
return SYS_USBHS_Init(&sys_usbhs_cfg);
}
int usb_shutdown_cb()
{
return SYS_USBHS_Shutdown();
return SYS_USBHS_Shutdown();
}
/* User-supplied function to delay usec micro-seconds */
void delay_us(unsigned int usec)
{
/* mxc_delay() takes unsigned long, so can't use it directly */
mxc_delay(usec);
/* mxc_delay() takes unsigned long, so can't use it directly */
mxc_delay(usec);
}
void bootloader_stop(void)
{
card10_reset();
}
void bootloader_dirty(void)
{
bootloader_display_line(4, "Writing.", 0xf000);
}
void bootloader_clean(void)
{
bootloader_display_line(4, "Ready. ", 0xffff);
}
/******************************************************************************/
void run_usbmsc(void)
{
maxusb_cfg_options_t usb_opts;
printf("Waiting for VBUS...\n");
/* Initialize state */
configured = 0;
suspended = 0;
event_flags = 0;
remote_wake_en = 0;
/* Start out in full speed */
usb_opts.enable_hs = 0;
usb_opts.delay_us = delay_us; /* Function which will be used for delays */
usb_opts.init_callback = usb_startup_cb;
usb_opts.shutdown_callback = usb_shutdown_cb;
/* Initialize the usb module */
if (usb_init(&usb_opts) != 0) {
printf("usb_init() failed\n");
while (1);
}
/* Initialize the enumeration module */
if (enum_init() != 0) {
printf("enum_init() failed\n");
while (1);
}
/* Register enumeration data */
enum_register_descriptor(ENUM_DESC_DEVICE, (uint8_t*)&device_descriptor, 0);
enum_register_descriptor(ENUM_DESC_CONFIG, (uint8_t*)&config_descriptor, 0);
enum_register_descriptor(ENUM_DESC_STRING, lang_id_desc, 0);
enum_register_descriptor(ENUM_DESC_STRING, mfg_id_desc, 1);
enum_register_descriptor(ENUM_DESC_STRING, prod_id_desc, 2);
enum_register_descriptor(ENUM_DESC_STRING, serial_id_desc, 3);
/* Handle configuration */
enum_register_callback(ENUM_SETCONFIG, setconfig_callback, NULL);
/* Handle feature set/clear */
enum_register_callback(ENUM_SETFEATURE, setfeature_callback, NULL);
enum_register_callback(ENUM_CLRFEATURE, clrfeature_callback, NULL);
/* Initialize the class driver */
if (msc_init(&config_descriptor.msc_interface_descriptor, &ids, &mem) != 0) {
printf("msc_init() failed\n");
while (1);
}
/* Register callbacks */
usb_event_enable(MAXUSB_EVENT_NOVBUS, event_callback, NULL);
usb_event_enable(MAXUSB_EVENT_VBUS, event_callback, NULL);
/* Start with USB in low power mode */
usb_app_sleep();
NVIC_EnableIRQ(USB_IRQn);
/* Wait for events */
while (1) {
if (suspended || !configured) {
//LED_Off(0);
} else {
//LED_On(0);
}
if (event_flags) {
/* Display events */
if (MXC_GETBIT(&event_flags, MAXUSB_EVENT_NOVBUS)) {
MXC_CLRBIT(&event_flags, MAXUSB_EVENT_NOVBUS);
printf("VBUS Disconnect\n");
} else if (MXC_GETBIT(&event_flags, MAXUSB_EVENT_VBUS)) {
MXC_CLRBIT(&event_flags, MAXUSB_EVENT_VBUS);
printf("VBUS Connect\n");
} else if (MXC_GETBIT(&event_flags, MAXUSB_EVENT_BRST)) {
MXC_CLRBIT(&event_flags, MAXUSB_EVENT_BRST);
printf("Bus Reset\n");
} else if (MXC_GETBIT(&event_flags, MAXUSB_EVENT_SUSP)) {
MXC_CLRBIT(&event_flags, MAXUSB_EVENT_SUSP);
printf("Suspended\n");
} else if (MXC_GETBIT(&event_flags, MAXUSB_EVENT_DPACT)) {
MXC_CLRBIT(&event_flags, MAXUSB_EVENT_DPACT);
printf("Resume\n");
} else if (MXC_GETBIT(&event_flags, EVENT_ENUM_COMP)) {
MXC_CLRBIT(&event_flags, EVENT_ENUM_COMP);
printf("Enumeration complete.\n");
} else if (MXC_GETBIT(&event_flags, EVENT_REMOTE_WAKE)) {
MXC_CLRBIT(&event_flags, EVENT_REMOTE_WAKE);
printf("Remote Wakeup\n");
}
}
card10_poll();
}
maxusb_cfg_options_t usb_opts;
printf("Waiting for VBUS...\n");
/* Initialize state */
configured = 0;
suspended = 0;
event_flags = 0;
remote_wake_en = 0;
/* Start out in full speed */
usb_opts.enable_hs = 0;
usb_opts.delay_us =
delay_us; /* Function which will be used for delays */
usb_opts.init_callback = usb_startup_cb;
usb_opts.shutdown_callback = usb_shutdown_cb;
/* Initialize the usb module */
if (usb_init(&usb_opts) != 0) {
printf("usb_init() failed\n");
while (1)
;
}
/* Initialize the enumeration module */
if (enum_init() != 0) {
printf("enum_init() failed\n");
while (1)
;
}
/* Register enumeration data */
enum_register_descriptor(
ENUM_DESC_DEVICE, (uint8_t *)&device_descriptor, 0
);
enum_register_descriptor(
ENUM_DESC_CONFIG, (uint8_t *)&config_descriptor, 0
);
enum_register_descriptor(ENUM_DESC_STRING, lang_id_desc, 0);
enum_register_descriptor(ENUM_DESC_STRING, mfg_id_desc, 1);
enum_register_descriptor(ENUM_DESC_STRING, prod_id_desc, 2);
enum_register_descriptor(ENUM_DESC_STRING, serial_id_desc, 3);
/* Handle configuration */
enum_register_callback(ENUM_SETCONFIG, setconfig_callback, NULL);
/* Handle feature set/clear */
enum_register_callback(ENUM_SETFEATURE, setfeature_callback, NULL);
enum_register_callback(ENUM_CLRFEATURE, clrfeature_callback, NULL);
/* Initialize the class driver */
if (msc_init(&config_descriptor.msc_interface_descriptor, &ids, &mem) !=
0) {
printf("msc_init() failed\n");
while (1)
;
}
/* Register callbacks */
usb_event_enable(MAXUSB_EVENT_NOVBUS, event_callback, NULL);
usb_event_enable(MAXUSB_EVENT_VBUS, event_callback, NULL);
/* Start with USB in low power mode */
usb_app_sleep();
NVIC_EnableIRQ(USB_IRQn);
/* Wait for events */
while (1) {
if (suspended || !configured) {
//LED_Off(0);
} else {
//LED_On(0);
}
if (event_flags) {
/* Display events */
if (MXC_GETBIT(&event_flags, MAXUSB_EVENT_NOVBUS)) {
MXC_CLRBIT(&event_flags, MAXUSB_EVENT_NOVBUS);
printf("VBUS Disconnect\n");
} else if (MXC_GETBIT(&event_flags, MAXUSB_EVENT_VBUS)) {
MXC_CLRBIT(&event_flags, MAXUSB_EVENT_VBUS);
printf("VBUS Connect\n");
} else if (MXC_GETBIT(&event_flags, MAXUSB_EVENT_BRST)) {
MXC_CLRBIT(&event_flags, MAXUSB_EVENT_BRST);
printf("Bus Reset\n");
} else if (MXC_GETBIT(&event_flags, MAXUSB_EVENT_SUSP)) {
MXC_CLRBIT(&event_flags, MAXUSB_EVENT_SUSP);
printf("Suspended\n");
} else if (MXC_GETBIT(
&event_flags, MAXUSB_EVENT_DPACT)) {
MXC_CLRBIT(&event_flags, MAXUSB_EVENT_DPACT);
printf("Resume\n");
} else if (MXC_GETBIT(&event_flags, EVENT_ENUM_COMP)) {
MXC_CLRBIT(&event_flags, EVENT_ENUM_COMP);
printf("Enumeration complete.\n");
} else if (MXC_GETBIT(&event_flags, EVENT_REMOTE_WAKE)) {
MXC_CLRBIT(&event_flags, EVENT_REMOTE_WAKE);
printf("Remote Wakeup\n");
}
}
card10_poll();
}
}
/******************************************************************************/
static int setconfig_callback(usb_setup_pkt *sud, void *cbdata)
{
/* Confirm the configuration value */
if (sud->wValue == config_descriptor.config_descriptor.bConfigurationValue) {
configured = 1;
MXC_SETBIT(&event_flags, EVENT_ENUM_COMP);
return msc_configure(&msc_cfg); /* Configure the device class */
} else if (sud->wValue == 0) {
configured = 0;
return msc_deconfigure();
}
return -1;
/* Confirm the configuration value */
if (sud->wValue ==
config_descriptor.config_descriptor.bConfigurationValue) {
configured = 1;
MXC_SETBIT(&event_flags, EVENT_ENUM_COMP);
return msc_configure(&msc_cfg); /* Configure the device class */
} else if (sud->wValue == 0) {
configured = 0;
return msc_deconfigure();
}
return -1;
}
/******************************************************************************/
static int setfeature_callback(usb_setup_pkt *sud, void *cbdata)
{
if(sud->wValue == FEAT_REMOTE_WAKE) {
remote_wake_en = 1;
} else {
// Unknown callback
return -1;
}
return 0;
if (sud->wValue == FEAT_REMOTE_WAKE) {
remote_wake_en = 1;
} else {
// Unknown callback
return -1;
}
return 0;
}
/******************************************************************************/
static int clrfeature_callback(usb_setup_pkt *sud, void *cbdata)
{
if(sud->wValue == FEAT_REMOTE_WAKE) {
remote_wake_en = 0;
} else {
// Unknown callback
return -1;
}
return 0;
if (sud->wValue == FEAT_REMOTE_WAKE) {
remote_wake_en = 0;
} else {
// Unknown callback
return -1;
}
return 0;
}
/******************************************************************************/
static void usb_app_sleep(void)
{
/* TODO: Place low-power code here */
suspended = 1;
/* TODO: Place low-power code here */
suspended = 1;
}
/******************************************************************************/
static void usb_app_wakeup(void)
{
/* TODO: Place low-power code here */
suspended = 0;
/* TODO: Place low-power code here */
suspended = 0;
}
/******************************************************************************/
static int event_callback(maxusb_event_t evt, void *data)
{
/* Set event flag */
MXC_SETBIT(&event_flags, evt);
printf("event: %d\n", evt);
switch (evt) {
case MAXUSB_EVENT_NOVBUS:
usb_event_disable(MAXUSB_EVENT_BRST);
usb_event_disable(MAXUSB_EVENT_SUSP);
usb_event_disable(MAXUSB_EVENT_DPACT);
usb_disconnect();
configured = 0;
enum_clearconfig();
msc_deconfigure();
usb_app_sleep();
break;
case MAXUSB_EVENT_VBUS:
usb_event_clear(MAXUSB_EVENT_BRST);
usb_event_enable(MAXUSB_EVENT_BRST, event_callback, NULL);
usb_event_clear(MAXUSB_EVENT_SUSP);
usb_event_enable(MAXUSB_EVENT_SUSP, event_callback, NULL);
usb_connect();
usb_app_sleep();
break;
case MAXUSB_EVENT_BRST:
usb_app_wakeup();
enum_clearconfig();
msc_deconfigure();
configured = 0;
suspended = 0;
break;
case MAXUSB_EVENT_SUSP:
usb_app_sleep();
break;
case MAXUSB_EVENT_DPACT:
usb_app_wakeup();
break;
default:
break;
}
return 0;
/* Set event flag */
MXC_SETBIT(&event_flags, evt);
printf("event: %d\n", evt);
switch (evt) {
case MAXUSB_EVENT_NOVBUS:
usb_event_disable(MAXUSB_EVENT_BRST);
usb_event_disable(MAXUSB_EVENT_SUSP);
usb_event_disable(MAXUSB_EVENT_DPACT);
usb_disconnect();
configured = 0;
enum_clearconfig();
msc_deconfigure();
usb_app_sleep();
break;
case MAXUSB_EVENT_VBUS:
usb_event_clear(MAXUSB_EVENT_BRST);
usb_event_enable(MAXUSB_EVENT_BRST, event_callback, NULL);
usb_event_clear(MAXUSB_EVENT_SUSP);
usb_event_enable(MAXUSB_EVENT_SUSP, event_callback, NULL);
usb_connect();
usb_app_sleep();
break;
case MAXUSB_EVENT_BRST:
usb_app_wakeup();
enum_clearconfig();
msc_deconfigure();
configured = 0;
suspended = 0;
break;
case MAXUSB_EVENT_SUSP:
usb_app_sleep();
break;
case MAXUSB_EVENT_DPACT:
usb_app_wakeup();
break;
default:
break;
}
return 0;
}
/******************************************************************************/
void USB_IRQHandler(void)
{
usb_event_handler();
usb_event_handler();
}
#pragma once
#include <stdint.h>
/* Display */
void bootloader_display_init(void);
void bootloader_display_header(void);
void bootloader_display_error(char *errtype, char *line1, char *line2);
void bootloader_display_line(int line, char *string, uint16_t color);
/* USB */
void run_usbmsc(void);
void bootloader_stop(void);
void bootloader_dirty(void);
void bootloader_clean(void);
......@@ -6,8 +6,12 @@ BIN1="$2"
BIN2="$3"
BINOUT="$4"
dd if=/dev/zero ibs=1k count=448 2>/dev/null | tr "\000" "\377" > "$BINOUT"
dd if="$BIN1" of="$BINOUT" conv=notrunc 2>/dev/null
dd if="$BIN2" of="$BINOUT" conv=notrunc oflag=append 2>/dev/null
if [ "$(stat -c "%s" "${BIN1}")" -gt 589824 ]; then
echo "$0: ${BIN1} is too big to fit!" >&2
exit 1
fi
objcopy -I binary -O binary --pad-to=589824 --gap-fill=255 "${BIN1}" "$BINOUT"
cat "$BIN2" >>"$BINOUT"
"$PYTHON" "$(dirname "$0")/crc_patch.py" "$BINOUT"
......@@ -29,46 +29,44 @@
/* CRC16 implementation acording to CCITT standards */
static const unsigned short crc16tab[256]= {
0x0000,0x1021,0x2042,0x3063,0x4084,0x50a5,0x60c6,0x70e7,
0x8108,0x9129,0xa14a,0xb16b,0xc18c,0xd1ad,0xe1ce,0xf1ef,
0x1231,0x0210,0x3273,0x2252,0x52b5,0x4294,0x72f7,0x62d6,
0x9339,0x8318,0xb37b,0xa35a,0xd3bd,0xc39c,0xf3ff,0xe3de,
0x2462,0x3443,0x0420,0x1401,0x64e6,0x74c7,0x44a4,0x5485,
0xa56a,0xb54b,0x8528,0x9509,0xe5ee,0xf5cf,0xc5ac,0xd58d,
0x3653,0x2672,0x1611,0x0630,0x76d7,0x66f6,0x5695,0x46b4,
0xb75b,0xa77a,0x9719,0x8738,0xf7df,0xe7fe,0xd79d,0xc7bc,
0x48c4,0x58e5,0x6886,0x78a7,0x0840,0x1861,0x2802,0x3823,
0xc9cc,0xd9ed,0xe98e,0xf9af,0x8948,0x9969,0xa90a,0xb92b,
0x5af5,0x4ad4,0x7ab7,0x6a96,0x1a71,0x0a50,0x3a33,0x2a12,
0xdbfd,0xcbdc,0xfbbf,0xeb9e,0x9b79,0x8b58,0xbb3b,0xab1a,
0x6ca6,0x7c87,0x4ce4,0x5cc5,0x2c22,0x3c03,0x0c60,0x1c41,
0xedae,0xfd8f,0xcdec,0xddcd,0xad2a,0xbd0b,0x8d68,0x9d49,
0x7e97,0x6eb6,0x5ed5,0x4ef4,0x3e13,0x2e32,0x1e51,0x0e70,
0xff9f,0xefbe,0xdfdd,0xcffc,0xbf1b,0xaf3a,0x9f59,0x8f78,
0x9188,0x81a9,0xb1ca,0xa1eb,0xd10c,0xc12d,0xf14e,0xe16f,
0x1080,0x00a1,0x30c2,0x20e3,0x5004,0x4025,0x7046,0x6067,
0x83b9,0x9398,0xa3fb,0xb3da,0xc33d,0xd31c,0xe37f,0xf35e,
0x02b1,0x1290,0x22f3,0x32d2,0x4235,0x5214,0x6277,0x7256,
0xb5ea,0xa5cb,0x95a8,0x8589,0xf56e,0xe54f,0xd52c,0xc50d,
0x34e2,0x24c3,0x14a0,0x0481,0x7466,0x6447,0x5424,0x4405,
0xa7db,0xb7fa,0x8799,0x97b8,0xe75f,0xf77e,0xc71d,0xd73c,
0x26d3,0x36f2,0x0691,0x16b0,0x6657,0x7676,0x4615,0x5634,
0xd94c,0xc96d,0xf90e,0xe92f,0x99c8,0x89e9,0xb98a,0xa9ab,
0x5844,0x4865,0x7806,0x6827,0x18c0,0x08e1,0x3882,0x28a3,
0xcb7d,0xdb5c,0xeb3f,0xfb1e,0x8bf9,0x9bd8,0xabbb,0xbb9a,
0x4a75,0x5a54,0x6a37,0x7a16,0x0af1,0x1ad0,0x2ab3,0x3a92,
0xfd2e,0xed0f,0xdd6c,0xcd4d,0xbdaa,0xad8b,0x9de8,0x8dc9,
0x7c26,0x6c07,0x5c64,0x4c45,0x3ca2,0x2c83,0x1ce0,0x0cc1,
0xef1f,0xff3e,0xcf5d,0xdf7c,0xaf9b,0xbfba,0x8fd9,0x9ff8,
0x6e17,0x7e36,0x4e55,0x5e74,0x2e93,0x3eb2,0x0ed1,0x1ef0
static const unsigned short crc16tab[256] = {
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, 0x8108,
0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, 0x1231, 0x0210,
0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, 0x9339, 0x8318, 0xb37b,
0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, 0x2462, 0x3443, 0x0420, 0x1401,
0x64e6, 0x74c7, 0x44a4, 0x5485, 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee,
0xf5cf, 0xc5ac, 0xd58d, 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6,
0x5695, 0x46b4, 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d,
0xc7bc, 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,
0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, 0x5af5,
0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, 0xdbfd, 0xcbdc,
0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, 0x6ca6, 0x7c87, 0x4ce4,
0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, 0xedae, 0xfd8f, 0xcdec, 0xddcd,
0xad2a, 0xbd0b, 0x8d68, 0x9d49, 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13,
0x2e32, 0x1e51, 0x0e70, 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a,
0x9f59, 0x8f78, 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e,
0xe16f, 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, 0x02b1,
0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, 0xb5ea, 0xa5cb,
0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, 0x34e2, 0x24c3, 0x14a0,
0x0481, 0x7466, 0x6447, 0x5424, 0x4405, 0xa7db, 0xb7fa, 0x8799, 0x97b8,
0xe75f, 0xf77e, 0xc71d, 0xd73c, 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657,
0x7676, 0x4615, 0x5634, 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9,
0xb98a, 0xa9ab, 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882,
0x28a3, 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, 0xfd2e,
0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, 0x7c26, 0x6c07,
0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, 0xef1f, 0xff3e, 0xcf5d,
0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, 0x6e17, 0x7e36, 0x4e55, 0x5e74,
0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
};
unsigned short crc16_ccitt(uint16_t oldcrc, const void *buf, int len)
{
register int counter;
register unsigned short crc = oldcrc;
for( counter = 0; counter < len; counter++)
crc = (crc<<8) ^ crc16tab[((crc>>8) ^ *(char *)buf++)&0x00FF];
for (counter = 0; counter < len; counter++)
crc = (crc << 8) ^
crc16tab[((crc >> 8) ^ *(char *)buf++) & 0x00FF];
return crc;
}
#!/usr/bin/env python3
import sys
import crc16
import warnings
warnings.simplefilter("ignore")
try:
import crc16
crcfun = crc16.crc16xmodem
except ImportError:
try:
import crcmod
crcfun = crcmod.predefined.mkCrcFun("xmodem")
except ImportError:
try:
import crcelk
crcfun = crcelk.CRC_XMODEM.calc_bytes
except ImportError:
raise Exception(
"Could not find a CRC implementation. Tried: crc16, crcmod, crcelk."
)
def main():
data = open(sys.argv[1], 'rb').read()
crc = crc16.crc16xmodem(data)
data = open(sys.argv[1], "rb").read()
crc = crcfun(data)
# print(crc)
padded = data + bytes([crc >> 8, crc & 0xFF])
crc = crc16.crc16xmodem(padded)
crc = crcfun(padded)
# print(crc)
open(sys.argv[1], 'wb').write(padded)
open(sys.argv[1], "wb").write(padded)
if __name__ == "__main__":
......
source ../init.gdb
file ../build/bootloader/bootloader.elf
#include <stdio.h>
#include <stddef.h>
#include <stdbool.h>
#include <string.h>
#include "bootloader.h"
#include "card10-version.h"
#include "mxc_config.h"
#include "mxc_sys.h"
#include "mxc_delay.h"
#include "flc.h"
#include "icc.h"
#include "i2c.h"
#include "crc.h"
#include "board.h"
#include "card10.h"
#include "led.h"
#include "ff.h"
#include "crc16-ccitt.h"
#include "pb.h"
#include "display.h"
#include "GUI_Paint.h"
#include "card10.h"
#include "pmic.h"
#define GPIO_PORT_IN PORT_1
#define GPIO_PIN_IN PIN_6
#include "board.h"
#include "crc.h"
#include "crc16-ccitt.h"
#include "ff.h"
#include "flc.h"
#include "i2c.h"
#include "icc.h"
#include "mxc_config.h"
#include "mxc_delay.h"
#include "mxc_sys.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#define GPIO_PORT_IN PORT_1
#define GPIO_PIN_IN PIN_6
#define PARTITION_START (0x10000000 + 64 * 1024)
#define PARTITION_END (0x10000000 + 1024 * 1024 - 1)
extern void run_usbmsc(void);
DIR dir;
FATFS FatFs;
bool mount(void)
int format(void)
{
FRESULT res;
res=f_mount(&FatFs,"/",0);
if(res != FR_OK) {
printf("f_mount error %d\n", res);
return false;
}
res = f_opendir(&dir, "0:");
if(res != FR_OK) {
printf("f_opendir error %d\n", res);
return false;
}
return true;
BYTE work[FF_MAX_SS * 16];
/* Create FAT volume */
int res = f_mkfs("", FM_ANY | FM_SFD, 0, work, sizeof work);
if (res != FR_OK) {
printf("Failed to make new FS %d\n", res);
return -1;
}
f_setlabel("card10");
if (res != FR_OK) {
printf("Failed to set volume name %d\n", res);
return -1;
}
return 0;
}
bool check_integrity(void)
int mount(void)
{
FIL file;
UINT readbytes;
char *filename = "card10.bin";
uint8_t data[512];
FRESULT res;
res=f_open(&file, filename, FA_OPEN_EXISTING|FA_READ);
if(res != FR_OK) {
printf("f_open error %d\n", res);
return false;
}
uint16_t crcval = 0;
do {
res = f_read(&file, data, sizeof(data), &readbytes);
if(res != FR_OK) {
printf("f_read error %d\n", res);
crcval = 1; // Make sure to fail the test
break;
}
crcval = crc16_ccitt(crcval, data, readbytes);
} while (readbytes == sizeof(data));
f_close(&file);
if(crcval == 0) {
return true;
} else {
printf("CRC check failed. Final CRC: %d\n", crcval);
return false;
}
FRESULT res;
res = f_mount(&FatFs, "/", 0);
if (res != FR_OK) {
printf("f_mount error %d\n", res);
return -1;
}
res = f_opendir(&dir, "0:");
if (res != FR_OK) {
printf("f_opendir error %d\n", res);
return -1;
}
return 0;
}
int check_integrity(void)
{
FIL file;
UINT readbytes;
char *filename = "card10.bin";
uint8_t data[512];
FRESULT res;
res = f_open(&file, filename, FA_OPEN_EXISTING | FA_READ);
if (res != FR_OK) {
printf("f_open error %d\n", res);
return -ENOENT;
}
uint16_t crcval = 0;
do {
res = f_read(&file, data, sizeof(data), &readbytes);
if (res != FR_OK) {
printf("f_read error %d\n", res);
crcval = 1; // Make sure to fail the test
break;
}
crcval = crc16_ccitt(crcval, data, readbytes);
} while (readbytes == sizeof(data));
f_close(&file);
if (crcval != 0) {
printf("CRC check failed. Final CRC: %d\n", crcval);
return -EINVAL;
}
return 0;
}
bool is_update_needed(void)
{
FIL file;
UINT readbytes;
char *filename = "card10.bin";
uint8_t data[512];
FRESULT res;
res=f_open(&file, filename, FA_OPEN_EXISTING|FA_READ);
if(res != FR_OK) {
printf("f_open error %d\n", res);
return false;
}
uint8_t *partition = (uint8_t *)(intptr_t)PARTITION_START;
bool different = false;
do {
res = f_read(&file, data, sizeof(data), &readbytes);
if(res != FR_OK) {
printf("f_read error %d\n", res);
break; /* Going to return false, don't want to use this file */
}
if(memcmp(partition, data, readbytes)) {
different = true;
break;
}
partition += readbytes;
} while (readbytes == sizeof(data));
f_close(&file);
return different;
FIL file;
UINT readbytes;
char *filename = "card10.bin";
uint8_t data[512];
FRESULT res;
res = f_open(&file, filename, FA_OPEN_EXISTING | FA_READ);
if (res != FR_OK) {
printf("f_open error %d\n", res);
return false;
}
uint8_t *partition = (uint8_t *)(intptr_t)PARTITION_START;
bool different = false;
do {
res = f_read(&file, data, sizeof(data), &readbytes);
if (res != FR_OK) {
printf("f_read error %d\n", res);
break; /* Going to return false, don't want to use this file */
}
if (memcmp(partition, data, readbytes)) {
different = true;
break;
}
partition += readbytes;
} while (readbytes == sizeof(data));
f_close(&file);
return different;
}
void erase_partition(void)
{
int ret = FLC_MultiPageErase(PARTITION_START, PARTITION_END);
if(ret != E_NO_ERROR) {
printf("FLC_MultiPageErase failed with %d\n", ret);
while(1);
}
int ret = FLC_MultiPageErase(PARTITION_START, PARTITION_END);
if (ret != E_NO_ERROR) {
printf("FLC_MultiPageErase failed with %d\n", ret);
while (1)
;
}
}
void flash_partition(void)
{
FIL file;
UINT readbytes;
char *filename = "card10.bin";
uint8_t data[512];
FRESULT res;
res=f_open(&file, filename, FA_OPEN_EXISTING|FA_READ);
if(res != FR_OK) {
printf("f_open error %d\n", res);
while(1);
}
uint32_t partition = PARTITION_START;
ICC_Disable();
do {
res = f_read(&file, data, sizeof(data), &readbytes);
if(res != FR_OK) {
printf("f_read error %d\n", res);
break; /* Going to return false, don't want to use this file */
}
int ret = FLC_Write(partition, readbytes, (uint32_t *)data); /* wild cast. not sure if this works */
if(ret != E_NO_ERROR) {
printf("FLC_Write failed with %d\n", ret);
while(1);
}
partition += readbytes;
} while (readbytes == sizeof(data));
ICC_Enable();
f_close(&file);
FIL file;
UINT readbytes;
char *filename = "card10.bin";
uint8_t data[512];
FRESULT res;
res = f_open(&file, filename, FA_OPEN_EXISTING | FA_READ);
if (res != FR_OK) {
printf("f_open error %d\n", res);
while (1)
;
}
uint32_t partition = PARTITION_START;
ICC_Disable();
do {
res = f_read(&file, data, sizeof(data), &readbytes);
if (res != FR_OK) {
printf("f_read error %d\n", res);
break; /* Going to return false, don't want to use this file */
}
int ret = FLC_Write(
partition,
readbytes,
(uint32_t *
)
data); /* wild cast. not sure if this works */
if (ret != E_NO_ERROR) {
printf("FLC_Write failed with %d\n", ret);
bootloader_display_error(
"Firmware Write", "Firmware not", "updated."
);
while (1)
;
}
partition += readbytes;
} while (readbytes == sizeof(data));
ICC_Enable();
f_close(&file);
}
static inline void boot(const void * vtable){
SCB->VTOR = (uintptr_t) vtable;
static inline void boot(const void *vtable)
{
SCB->VTOR = (uintptr_t)vtable;
// Reset stack pointer & branch to the new reset vector.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated"
__asm( "mov r0, %0\n"
"ldr sp, [r0]\n"
"ldr r0, [r0, #4]\n"
"bx r0\n"
:
: "r"(vtable)
: "%sp", "r0");
__asm("mov r0, %0\n"
"ldr sp, [r0]\n"
"ldr r0, [r0, #4]\n"
"bx r0\n"
:
: "r"(vtable)
: "%sp", "r0");
#pragma GCC diagnostic pop
};
static void pmic_button(bool falling)
{
if (falling) {
printf("Resetting ...\n");
/*
* Give the UART fifo time to clear.
* TODO: Do this properly
*/
for (int i = 0; i < 0x1000000; i++) {
__asm volatile("nop");
}
MXC_GCR->rstr0 = MXC_F_GCR_RSTR0_SYSTEM;
card10_reset();
}
}
static void msc(void)
{
bootloader_display_header();
bootloader_display_line(3, "USB activated.", 0xffff);
bootloader_display_line(4, "Ready.", 0xffff);
run_usbmsc();
// If we return, don't try to boot. Maybe rather trigger a software reset.
// Reason: Not sure in which state the USB peripheral is and what kind
// of interrupts are active.
while (1)
;
}
/******************************************************************************/
int main(void)
{
printf("\n\nBootloader\n");
card10_init();
pmic_set_button_callback(pmic_button);
Paint_DrawString_EN(0, 16*0, "Bootloader", &Font16, 0x0000, 0xffff);
Paint_DrawString_EN(0, 16*1, __DATE__, &Font16, 0x0000, 0xffff);
LCD_Update();
// If the button is pressed, we go into MSC mode.
if (PB_Get(3)) {
Paint_DrawString_EN(0, 16*2, "USB activated. Waiting.", &Font16, 0x0000, 0xffff);
LCD_Update();
run_usbmsc();
// If we return, don't try to boot. Maybe rather trigger a software reset.
// Reason: Not sure in which state the USB peripheral is and what kind
// of interrupts are active.
while(1);
}
if(mount()) {
if(check_integrity()) {
printf("Found valid application image\n");
if(is_update_needed()) {
printf("Trying to update application from external flash\n");
Paint_DrawString_EN(0, 16*4, "Updating...", &Font16, 0x0000, 0xffff);
LCD_Update();
erase_partition();
flash_partition();
} else {
printf("No update needed\n");
}
} else {
Paint_DrawString_EN(0, 16*2, "Integrity check failed", &Font16, 0x0000, 0xffff);
LCD_Update();
printf("Integrity check failed\n");
}
} else {
Paint_DrawString_EN(0, 16*2, "Failed to mount file system", &Font16, 0x0000, 0xffff);
LCD_Update();
printf("Failed to mount the external flash\n");
}
printf("Trying to boot\n");
Paint_DrawString_EN(0, 16*4, "Trying to boot", &Font16, 0x0000, 0xffff);
LCD_Update();
//while(1);
// boot partition
boot((uintptr_t *) PARTITION_START);
while (1) {
// Should never be reached.
}
printf("\n\nBootloader " CARD10_VERSION "\n");
card10_init();
/*
* Make the power/reset button restart card10.
*/
pmic_set_button_callback(pmic_button);
bootloader_display_init();
// If the button is pressed, we go into MSC mode.
if (PB_Get(3)) {
msc();
}
if (mount() == 0) {
int res = check_integrity();
if (res == -ENOENT) {
printf("card10.bin not found!\n");
} else if (res == -EINVAL) {
printf("card10.bin CRC is invalid!\n");
bootloader_display_header();
bootloader_display_line(
3, "Integrity check failed", 0xffff
);
bootloader_display_line(4, "Trying to boot", 0xffff);
} else if (res == 0) {
printf("Found valid application image\n");
if (is_update_needed()) {
printf("Trying to update firmware from external flash\n");
bootloader_display_header();
bootloader_display_line(
4, "Updating ...", 0xffff
);
erase_partition();
flash_partition();
f_unlink("card10.bin");
bootloader_display_line(
4, "Trying to boot", 0xffff
);
} else {
printf("No update needed\n");
}
}
} else {
bootloader_display_header();
bootloader_display_line(3, "Creating new filesystem", 0xffff);
printf("Creating new filesystem\n");
if (format() == 0) {
/* Drop into MSC after a reboot */
card10_reset();
} else {
bootloader_display_line(
3, "Failed to create new filesystem", 0xffff
);
printf("Feiled to create new filesystem\n");
/* Prevent bootloops */
while (1) {
}
}
}
/* Get the intital SP of the firmware. If it is 0xFFFFFFFF, no image has been
* flashed yet. Drop into MSC for initial flashing. */
if (*((uint32_t *)PARTITION_START) == 0xFFFFFFFF) {
printf("No valid image in flash\n");
msc();
}
printf("Trying to boot\n");
boot((uintptr_t *)PARTITION_START);
while (1) {
// Should never be reached.
}
}
/******************************************************************************/
void SysTick_Handler(void)
{
mxc_delay_handler();
mxc_delay_handler();
}
name = 'bootloader'
splash_screen = custom_target(
'splash-screen.h',
output: 'splash-screen.h',
input: 'splash-screen.png',
command: [
python3,
meson.current_source_dir() + '../tools/bootloader-image.py',
'-n', 'splash',
'@INPUT@',
'@OUTPUT@',
],
)
executable(
name + '.elf',
'main.c',
'mscmem.c',
'bootloader-display.c',
'bootloader-usb.c',
'crc16-ccitt.c',
splash_screen,
version_hdr,
dependencies: [
libcard10,
max32665_startup_boot,
......
#include "bootloader.h"
#include "mscmem.h"
#include "mx25lba.h"
#include <string.h>
#include <stdio.h>
#include "mx25lba.h"
static int dirty = 0;
/******************************************************************************/
int mscmem_init()
{
printf("%s\n", __func__);
printf("%s\n", __func__);
return mx25_init();
}
/******************************************************************************/
uint32_t mscmem_size(void)
{
printf("%s\n", __func__);
printf("%s\n", __func__);
return mx25_size();
}
/******************************************************************************/
int mscmem_read(uint32_t lba, uint8_t* buffer)
int mscmem_read(uint32_t lba, uint8_t *buffer)
{
//printf("%s\n", __func__);
//printf("%s\n", __func__);
return mx25_read(lba, buffer);
}
/******************************************************************************/
int mscmem_write(uint32_t lba, uint8_t* buffer)
int mscmem_write(uint32_t lba, uint8_t *buffer)
{
//printf("%s\n", __func__);
return mx25_write(lba, buffer);
//printf("%s\n", __func__);
if (dirty == 0) {
bootloader_dirty();
}
dirty = 2;
return mx25_write(lba, buffer);
}
/******************************************************************************/
int mscmem_start()
{
printf("%s\n", __func__);
return mx25_start();
printf("%s\n", __func__);
return mx25_start();
}
/******************************************************************************/
int mscmem_stop()
{
printf("%s\n", __func__);
return mx25_stop();
printf("%s\n", __func__);
int ret = mx25_stop();
bootloader_stop();
return ret;
}
/******************************************************************************/
int mscmem_ready()
{
//printf("%s\n", __func__);
return mx25_ready();
//printf("%s\n", __func__);
if (dirty) {
dirty--;
if (dirty == 0) {
printf("sync\n");
mx25_sync();
bootloader_clean();
}
}
return mx25_ready();
}
bootloader/splash-screen.png

6.1 KiB

......@@ -4,8 +4,10 @@ set -xe
cd "$(dirname "$0")"
test -d build/ && rm -r build/
git submodule update --init ./lib/micropython
meson --cross-file card10-cross.ini build/
# Get external libs (MicroPython, tiny-AES-c, SHA256)
git submodule deinit --all
git submodule update --init ./lib
meson --cross-file card10-cross.ini build/ "$@"
set +x
......
......@@ -4,9 +4,9 @@ ar = 'arm-none-eabi-ar'
strip = 'arm-none-eabi-strip'
[properties]
c_args = ['-mthumb', '-mcpu=cortex-m4', '-mfloat-abi=hard', '-mfpu=fpv4-sp-d16', '-Wa,-mimplicit-it=thumb', '-ffunction-sections', '-fdata-sections', '-fsingle-precision-constant', '-fno-isolate-erroneous-paths-dereference', '-Wl,--start-group', '-lc', '-lnosys', '-Wl,--end-group']
c_args = ['-mthumb', '-mcpu=cortex-m4', '-mfloat-abi=softfp', '-mfpu=fpv4-sp-d16', '-Wa,-mimplicit-it=thumb', '-ffunction-sections', '-fdata-sections', '-fsingle-precision-constant', '-fno-isolate-erroneous-paths-dereference']
c_link_args = ['-mthumb', '-mcpu=cortex-m4', '-mfloat-abi=hard', '-mfpu=fpv4-sp-d16', '-Wl,--start-group', '-lc', '-lnosys', '-Wl,--end-group', '--specs=nano.specs', '-u _printf_float']
c_link_args = ['-mthumb', '-mcpu=cortex-m4', '-mfloat-abi=softfp', '-mfpu=fpv4-sp-d16', '-Wl,--start-group', '-lc', '-lnosys', '-Wl,--end-group', '--specs=nano.specs', '-Wl,-wrap,BbBleDrvRand']
target_defs = ['-DTARGET=32665', '-DTARGET_REV=0x4131', '-DBOARD_CARD10=1']
......