Close

Some tests and pitfalls

A project log for BlackMath

"BlackMath" is a small DSP board, based on Blackfin BF592A, using an Arduino-compatible as loader and PC interface.

Marcellus PereiraMarcellus Pereira 11/16/2018 at 20:580 Comments

Well, this first version of the board has it's flaws, but I could run some tests.

I used the Analog Devices JTAG tool to load 2204, 16 bit audio samples and a simple 100 taps convolution filter. Then, I rewrote the code using the BF592 ROM routines and compared the results: from 64ms to 0,6ms.

Of course, the convolution filter used an academic code, but, yet, I think this will amaze the students.

The downside of the test: I discovered that the CODEC SGTL5000, when wired to SPI interface, can not be read. So, I thought I could use the chip ID register to just test the SPI interface but that is impossible.

I wrote a simple Arduino program to receive the LDR file and store it, in the hope to use it to boot the DSP. But I chose the UART as the main boot interface (from Arduino to DSP), and forgot that Arduino uses it as its main PC interface.

Now, I will have to write a small bootloader, load it in the BlackMath's SPI Flash and use the second SPI, attached to Arduino, to read the LDR binary.

Just as curiosity, the Arduino code (based on multiple internet sources),  is as follows:

/*
   Copyright (c) 2015, Majenko Technologies
   All rights reserved.

   Redistribution and use in source and binary forms, with or without modification,
   are permitted provided that the following conditions are met:

 * * Redistributions of source code must retain the above copyright notice, this
     list of conditions and the following disclaimer.

 * * Redistributions in binary form must reproduce the above copyright notice, this
     list of conditions and the following disclaimer in the documentation and/or
     other materials provided with the distribution.

 * * Neither the name of Majenko Technologies nor the names of its
     contributors may be used to endorse or promote products derived from
     this software without specific prior written permission.

   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
   ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
   ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
Modified by Marcellus Pereira <marcellus at laboratoriosacme.net>
*/

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <FS.h>   // Include the SPIFFS library 

const char *ssid = "myssid";
const char *password = "mypassword";

ESP8266WebServer server(80);

const int led = 14;
const char page[] = {"<html><head><title></title></head><body><h1 style=\"text-align: center;\"><span style=\"font-family:courier new,courier,monospace;\"><strong>BlackMath</strong></span></h1><p><span style=\"font-family:courier new,courier,monospace;\">Atualização de firmware.</span></p><form action=\"update\" enctype=\"multipart/form-data\" method=\"post\">Arquivo ldr: <input id=\"fileToUpload\" name=\"fileToUpload\" type=\"file\" /> <input name=\"submit\" type=\"submit\" value=\"Atualizar\" /> </form><p> </p></body></html>"};


File fsUploadFile;              // a File object to temporarily store the received file

void handleRoot() {
  digitalWrite(led, 1);
  char temp[600];
  int sec = millis() / 1000;
  int min = sec / 60;
  int hr = min / 60;

  server.send(200, "text/html", page);
  digitalWrite(led, 0);
}

void handleNotFound() {
  digitalWrite(led, 1);
  String message = "File Not Found\n\n";
  message += "URI: ";
  message += server.uri();
  message += "\nMethod: ";
  message += (server.method() == HTTP_GET) ? "GET" : "POST";
  message += "\nArguments: ";
  message += server.args();
  message += "\n";

  for (uint8_t i = 0; i < server.args(); i++) {
    message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
  }

  server.send(404, "text/plain", message);
  digitalWrite(led, 0);
}

void setup(void) {
  pinMode(led, OUTPUT);
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(led, 0);
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  Serial.println("");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  if (MDNS.begin("blackmath")) {
    Serial.println("MDNS responder started");
  }

  SPIFFS.begin();                           // Start the SPI Flash Files System

  server.on("/", handleRoot);
  server.on("/update", HTTP_POST,                       // if the client posts to the upload page
    [](){ server.send(200); },                          // Send status 200 (OK) to tell the client we are ready to receive
    hUpdate                                    // Receive and save the file
  );
  server.on("/inline", []() {
    server.send(200, "text/plain", "this works as well");
  });
server.onNotFound([]() {                              // If the client requests any URI
    if (!handleFileRead(server.uri()))                  // send it if it exists
      server.send(404, "text/plain", "404: Not Found"); // otherwise, respond with a 404 (Not Found) error
  });
  server.begin();
  Serial.println("HTTP server started");
}

void loop(void) {
  static int contador;
  server.handleClient();
  if(contador++ > 5000){
    digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
    contador = 0;
  }
}

void hUpdate(){ // upload a new file to the SPIFFS
  HTTPUpload& upload = server.upload();
  if(upload.status == UPLOAD_FILE_START){
    String filename = upload.filename;
    if(!filename.startsWith("/")) filename = "/"+filename;
    Serial.print("handleFileUpload Name: "); Serial.println(filename);
    fsUploadFile = SPIFFS.open(filename, "w");            // Open the file for writing in SPIFFS (create if it doesn't exist)
    filename = String();
  } else if(upload.status == UPLOAD_FILE_WRITE){
    if(fsUploadFile)
      fsUploadFile.write(upload.buf, upload.currentSize); // Write the received bytes to the file
  } else if(upload.status == UPLOAD_FILE_END){
    if(fsUploadFile) {                                    // If the file was successfully created
      fsUploadFile.close();                               // Close the file again
      Serial.print("handleFileUpload Size: "); Serial.println(upload.totalSize);
      server.sendHeader("Location","/success.html");      // Redirect the client to the success page
      server.send(303);
    } else {
      server.send(500, "text/plain", "500: couldn't create file");
    }
  }
}


String getContentType(String filename) { // convert the file extension to the MIME type
  if (filename.endsWith(".html")) return "text/html";
  else if (filename.endsWith(".css")) return "text/css";
  else if (filename.endsWith(".js")) return "application/javascript";
  else if (filename.endsWith(".ico")) return "image/x-icon";
  else if (filename.endsWith(".gz")) return "application/x-gzip";
  return "text/plain";
}

bool handleFileRead(String path) { // send the right file to the client (if it exists)
  Serial.println("handleFileRead: " + path);
  if (path.endsWith("/")) path += "index.html";          // If a folder is requested, send the index file
  String contentType = getContentType(path);             // Get the MIME type
  String pathWithGz = path + ".gz";
  if (SPIFFS.exists(pathWithGz) || SPIFFS.exists(path)) { // If the file exists, either as a compressed archive, or normal
    if (SPIFFS.exists(pathWithGz))                         // If there's a compressed version available
      path += ".gz";                                         // Use the compressed verion
    File file = SPIFFS.open(path, "r");                    // Open the file
    size_t sent = server.streamFile(file, contentType);    // Send it to the client
    file.close();                                          // Close the file again
    Serial.println(String("\tSent file: ") + path);
    return true;
  }
  Serial.println(String("\tFile Not Found: ") + path);   // If the file doesn't exist, return false
  return false;
}

 Just to find out the Bonjour service doesn't work very well on Windows 10... :-(

Discussions