Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New files for Tensorflow Lite Micro Speech Example targetting the Eta… #24222

Merged
merged 8 commits into from Dec 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,32 @@
Running The Micro Speech Example On Eta Compute's ECM3531EVB

This code will enable you to compile and execute the Tensorflow Lite Micro Speech Example on Eta Computes's low power ECM3531 chip.


GETTING STARTED:

1. Download the Tensorflow code from Github and follow instructions there to download other dependencies.

2. Download the Eta Compute SDK, version 0.0.17.

3. Install the Arm compiler arm-none-eabi-gcc, version = arm-none-eabi-gcc (GNU Tools for Arm Embedded Processors 7-2018-q2-update) 7.3.1 20180622 (release) [ARM/embedded-7-branch revision 261907]

4. Edit the file tensorflow/lite/experimental/micro/tools/make/targets/ecm3531_makefile.inc so that the variable ETA_SDK points to the location where the Eta Compute SDK is installed, and the variable GCC_ARM points to the Arm compiler.

5. Compile the code with the command "make -f tensorflow/lite/experimental/micro/tools/make/Makefile TARGET=ecm3531 test". This will create the executable tensorflow/lite/experimental/micro/tools/make/gen/ecm3531_cortex-m3/bin/micro_speech_test.

6. Connect the board to the host computer, start PuTTY (Connection type = Serial, Speed = 11520, Data bits = 8, Stop bits = 1, Parity = None), and load the executable with ocd. A sample script for loading the image is provided in tensorflow/lite/experimental/micro/tools/make/targets/ecm3531/load_program.

The following will be printed on the Uart:

Testing TestInvoke
Ran successfully

/ tests passed
~~~ALL TESTS PASSED~~~



CONTACT INFORMATION:

Contact info@etacompute.com for more information on obtaining the Eta Compute SDK and evalution board.
@@ -0,0 +1,95 @@
/* Copyright 2015 The TensorFlow Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

/* This is file contains the entry point to the application and is called after
startup.
The GPIOs, Uart and timer are intialized and Tensorflow is invoked with the
call to main().
Tensorflow will print out if the tests have passed or failed and the
execution time is also
printed. */

#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "eta_bsp.h"
#include "eta_chip.h"
#include "eta_csp.h"
#include "eta_csp_buck.h"
#include "eta_csp_gpio.h"
#include "eta_csp_io.h"
#include "eta_csp_pwr.h"
#include "eta_csp_rtc.h"
#include "eta_csp_socctrl.h"
#include "eta_csp_sys_clock.h"
#include "eta_csp_timer.h"
#include "eta_csp_uart.h"

tUart g_sUart0 = {eUartNum0, eUartBaud115200};
tUart g_sUart1 = {eUartNum1, eUartBaud115200};

int init_main(int);
void EtaPrintExecutionTime(uint64_t);

//*****************************************************************************
//
// The entry point for the application.
//
//*****************************************************************************
extern int main(int argc, char** argv);

void DebugLog(const char* s) { EtaCspIoPrintf("%s", s); }
void DebugLogInt32(int32_t i) { EtaCspIoPrintf("%d", i); }
void DebugLogUInt32(uint32_t i) { EtaCspIoPrintf("%d", i); }
void DebugLogHex(uint32_t i) { EtaCspIoPrintf("0x%8x", i); }
void DebugLogFloat(float i) { EtaCspIoPrintf("%f", i); }

int _main(void) {
uint64_t time_ms;

EtaCspInit(); // initialize csp registers
EtaCspGpioInit(); // initialize gpios
EtaCspUartInit(&g_sUart1, eUartNum0, eUartBaud115200,
eUartFlowControlHardware); // initialize Uart
EtaCspBuckInit(ETA_BSP_VDD_IO_SETTING, eBuckAo600Mv, eBuckM3Frequency60Mhz,
eBuckMemVoltage900Mv); // set M3 freq
EtaCspTimerInitMs(); // start timer
main(0, NULL); // Call to Tensorflow; this will print if test was successful.
time_ms = EtaCspTimerCountGetMs(); // read time
EtaPrintExecutionTime(time_ms); // print execution time
}

void EtaPrintExecutionTime(uint64_t time_ms) {
uint8_t c;
int k1;
char time_string[] = "00000";

EtaCspIoPrintf("Execution time (msec) = ");
if (time_ms < 100000) // Convert time to a string
{
for (k1 = 0; k1 < 5; k1++) {
c = time_ms % 10;
time_ms = time_ms / 10;
time_string[k1] = (char)(0x30 + c);
}
for (k1 = 4; k1 > 0; k1--) { // print out 1 char at a time
EtaCspUartPutc(&g_sUart1, time_string[k1]);
}
} else {
EtaCspIoPrintf("Execution time exceeds 100 sec\n");
}
EtaCspIoPrintf("\n\n");
}
@@ -0,0 +1,85 @@
/* Copyright 2015 The TensorFlow Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/


/*
* linker script for use with ECM3531
* All sections must map to 128KBytes of SRAM beginning at 0x10000000
*
*/

/*
* Indicate to the linker the entry point.
*/
ENTRY(ResetISR)

/*
* SRAM is at 0x10000000 of length 0x00020000
*/
MEMORY
{
SRAM (RWX) : ORIGIN = 0x10000000, LENGTH = 0x00020000
}

SECTIONS
{
.text :
{
_text = .;
KEEP(*(.vectors))
. = ALIGN(0x4);
*(.text*)
. = ALIGN(0x4);
*(.rodata*)
. = ALIGN(0x4);
_etext = .;
} > SRAM= 0
.dummy :
{
. = ALIGN(0x4);
_eftext = .;
} > SRAM
.datax :
{
_datax = .;
KEEP(*(.mainStack))
. += 12288;
_edatax = .;
_stack_top = .;
. += 4;
} > SRAM
.data :
AT (ADDR(.text) + SIZEOF(.text) )
{
_data = .;
*(.data*)
KEEP(*(.mainHeap))
_edata = .;
} > SRAM

.bss :
{
_bss = .;
*(.bss*)
*(COMMON)
_ebss = .;
} > SRAM
.ARM.exidx :
{
*(.ARM.exidx*)
}

}

@@ -0,0 +1,53 @@
#!/usr/bin/python3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a copyright notice here?

Suggested change
#!/usr/bin/python3
#!/usr/bin/python3
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

#Usage: cd to the directory tensorflow/lite/experimental/micro/tools/make/targets/ecm3531 and type ./load_prgram to load the executable tensorflow/lite/experimental/micro/tools/make/gen/ecm3531_cortex-m3/bin/micro_speech_test into SRAM
#
#
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.
#==============================================================================


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a quick comment about usage, even if it's just pointing back to the main doc file?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

import os
import telnetlib

def send_ocd_cmd(line):
ocd_sock.write(bytes(line,encoding = 'utf-8'))
print(ocd_sock.read_until(b'> ').decode('utf-8'), end='')

def get_ocd_response():
print(ocd_sock.read_until(b'> ').decode('utf-8'), end='')

#get hooked up to openocd daemon
ocd_sock = telnetlib.Telnet(host='localhost', port=4444)
get_ocd_response() # clean it out

# git path to project elf file
cur_dir = os.getcwd()
elf_file = cur_dir + '/../../gen/ecm3531_cortex-m3/bin/' + 'micro_speech_test'
print("elf_file = ",elf_file)


# use these to download and run the elf fle
ocd_commands = ["halt\n",
"load_image {}\n".format(elf_file),
"mww 0x1001FFF8 0xDEADBEEF\n",
"mww 0x1001FFFC 0xC369A517\n",
"reset\n"]

# OK now do what we came here for!!!
for x in ocd_commands:
print(x)
send_ocd_cmd(x)