#I think I need to add some pull up resistors to a serial line too but I think I can reuse the resistors I'm pulling off for that luckily
Explore tagged Tumblr posts
Text
Number of mods needed on the new SDS7 CPU board: 1 2 17
#before they even arrived I realized I left the boot0 pin floating#which will fuck up the startup sequence if it floats to the wrong setting#then I realized I connected the +5V line from the USB to the rest of the +5V rail#which would mean 2 power supplies trying to provide 5V and they might fight to the death over it#and now I just realized I messed up a thing in the schematic which is used 14 different times for all of the op amp outputs#and then I messed up one other thing in one of the op amp circuits that requires removing 2 resistors but that simplifies the output mod#I think I need to add some pull up resistors to a serial line too but I think I can reuse the resistors I'm pulling off for that luckily#i haven't posted about this project in a while#oops#i have circuit boards now and I'm writing firmware for them
0 notes
Text
Getting the ESP8266 Code Ready for C
Espressif chips are the sexy mcu’s these days. If you’re reading this, it’s more likely because you’re already familiar with their with what they’ve got to offer. They made their first splash - and I mean like the bombest cannonball you’ve ever seen - with the esp8266 which explorers spent some good time opening the SDK and even going so far as decapping and tracing the silicon. The chip came as an oddly shaped module with 8 pins (the ESP8266-01) then exploded into a bunch of others.
I’m here to convince you to get one if you haven’t and experiment with me because there’s a world of possibility with these. If qualitative statements don’t do it for ya, then check out these specs mostly from its wikipedia entry:
32-bit CPU (Tensilica Xtensa L106 operating at 80MHz
64KiB of instruction RAM and 96KiB of data RAM
802.11 b/g/n wifi with WPA/WPA2, WEP, and open security
2 GPIOs exposed to us (their MUXed functions aren’t great-GPIO 0 is muxed to SPI chip select and GPIO 2 is muxed to I2C SDA... ^^; buuut...)
Each GPIO can be configured for pull-up, can trigger interrupts, be configured as open drain or push-pull. Reportedly (from the datasheet), we can also do PWM but it says in another breath that it is “software programmable” which I take to mean DIY.
500kB or 1MB external SPI flash on the module (not on the SoC)
Afraid you’re going to be spending too much to get all that? YOU CAN GET 4 FOR $14.00 SO NO EXCUSES!
Of course not all of the pins are exposed so that stinks and means we don’t get all of the functionality but we’ll see what we can do with what we’ve got and maybe I’ll do another blog entry if that’s what we’d like to do.
Anyway, I love these and think you should too. I wanted to share how to get as close to main() as possible, and how to make your own tiny programming jig so....let’s GO!
Hardware
Can’t start the software without a little hardware! We need to make a quick programming jig to move between “serial programming” and “run” mode.
I used parts-box parts but you can get similar parts from almost anywhere. Just in case, here’s an ingredients list:
3.3v FTDI cable/module
ESP8266-01
Push button switch (for the reset line which is active low. You’ll see I used a mouse button for some reason but if you use a push button, you’ll need a pull up resistor)
A latched push button (for power but I used another mouse button)
DPST/DPDT switch
Headers (both female and male)
Some perf board
Here are the pin configs for serial programming:
and so this is the schematic we’re after:
Again, I only had the parts I had so here’s the schematic with what I had:
And here’s a quick map of how the perfboard is laid out:
(The boxes and blue lines represent top-layer components and wires, the red lines represent solder mazes)
(Here’s the back side so you can basically put the parts in as in the first photo and solder the traces on the back like this photo)
When all is said and done, you end up with this:
Easy as pie and hardware part done!
Software
Alright, so next up let’s get the toolchain setup, upload the blinky code, modify, and upload again so we feel good and ready to move onto projects. I chose open-esp-sdk purely because others really liked it.
This process is pretty typical but here’s the idea:
Install Dependencies (apt-get) -> Clone the Repository (git) -> Build the Project (make) -> Globalize the Tools (assigning to a global)
Then it’s time to build the example and load it up on the ESP.
Build Blinky (make) -> Power Cycle the device in program mode -> Load the new binary to the board (esptool.py) -> drink beer in celebration
Setting up the Environment
Install the Dependencies - download and install all the programs that will help you build the environment, build the esp binaries and use the upload tools
sudo apt-get install make unrar-free autoconf automake libtool gcc g++ gperf flex \ bison texinfo gawk ncurses-dev libexpat-dev python-dev python python-serial \ sed git unzip bash help2man wget bzip2 libtool-bin
Clone the repository - for those who are new to git (many at my company were when they came aboard, obviously me included) all this is is just copying a project that someone has posted to git down to your computer. Make sure you go to the directory where you want your project to reside and type:
`git clone --recursive https://github.com/pfalcon/esp-open-sdk.git`
Build the Environment - When it’s done, cd into the esp-open-sdk directory and make the project
cd esp-open-sdkmake STANDALONE=y
The “STANDALONE=y” ensures you get the xtensa toolchain and the esp SDK.
Depending on your hardware this may take a while. Just for shits and giggles I installed it on my Crubuntu laptop which took an hour (to be fair I was watching netflix on the Chrome side). If it goes off without a hitch, it will report
Espressif ESP8266 SDK is installed, its libraries and headers are merged with the toolchain
Pitfalls
I’ve encountered two errors when I tried this though - one was when I followed the github instructions and didn’t try to install libtools-bin (since it said you may not require it). For safety, I just put it in my apt-get command above.
The other was because I had played around a bunch on my computer and had the LD_LIBRARY_PATH variable set to which it complained
[ERROR] Don't set LD_LIBRARY_PATH. It screws up the build.
If that happens, make sure you clear your LD_LIBRARY_PATH environmental variable with
unset LD_LIBRARY_PATH
and try again.
Globalize the Tools - We’ll want to make it so that we can access the xtensa gcc toolchain (which we’ll use to compile link and convert our sourcecode to ELF) and the esptools (which we’ll use to convert to a binary and write to flash locations on the chip over serial) everywhere. To make that happen, we need to add the path to xtensa-lx106-elf-gcc and esptool.py to the ~/.bashrc - the file that loads every time we load a terminal session.
There should have been a line above the success message that says Xtensa toolchain is built, to use it:
export PATH=[your_path_to_esp_open_sdk]/esp-open-sdk/xtensa-lx106-elf/bin:$PATH
Go ahead and do that - type:
export PATH=[your_path_to_esp_open_sdk]/esp-open-sdk/ xtensa-lx106-elf/bin:$PATH
But let’s also add it to our ~/.bashrc which controls what happens when we open a new terminal:
echo “export PATH=[your_path_to_esp_open_sdk]/esp-open-sdk/ xtensa-lx106-elf/bin:$PATH” >> ~/.bashrc
and then we’re good! To test if that worked, cd to the esp-open-sdk directory and then do
cd examples/blinky
and type
make
If that went through well (i.e. it didn’t throw any complaints to you), you’ve properly configured your environmental path variable. Now remove the blinky binaries (make seems to make different binary locations than those used in make flash and make clean)
rm -f blinky blinky.o blinky-0x00000.bin blinky-0x10000.bin
Testing with blinky.c
Our next goal is to run blinky on the board.
Test the Serial Port
First let’s make sure we have access to the serial port so we can program the device. Connect your FTDI programmer to your USB port and type
dmesg | grep FTDI
It should list a line like this to tell you which /dev the FTDI connected to like
usb 1-2: FTDI USB Serial Device converter now attached to ttyUSB0
Next, send something like (where ttyUSB0 is the device you got)
echo -ne “\r\n” > /dev/ttyUSB0
If you just get another prompt pop up immediately after, you shouldn’t have anything to worry about and can move to the next section. If you get the Permission Denied message, you need to add yourself to the same group as your FTDI port. Let’s find out which group we need to be a part of. Type:
ls -l /dev/ttyUSB0
and you should get something like:
crw-rw---- 1 root serial 188, 0 Jun 19 02:52 /dev/ttyUSB0
Many sites online just say to add to “dialout” but you see that my port is connected to the group “serial.” I can add myself to that group with:
sudo usermod -a -G serial alexmo
and then log out and log back in.
Now when you’re back in, if you retype
echo -ne “\r\n” > /dev/ttyUSB0
you shouldn’t see the permission denied message.
Build
Build with
make
You’ll see a few new files. The binaries marked blinky-0x00000.bin and blinky-0x10000.bin tell you where they should be written.
Program
Now let’s program the device with the binaries. If you see blinky-0x00000.bin and blinky-0x10000.bin, just type
esptool.py write_flash 0 blinky-0x00000.bin 0x10000 blinky-0x10000.bin
It will work on it:
esptool.py v1.2 Connecting... Auto-detected Flash size: 4m Running Cesanta flasher stub... Flash params set to 0x0000 Writing 36864 @ 0x0... 36864 (100 %) Wrote 36864 bytes at 0x0 in 3.2 seconds (91.5 kbit/s)... Writing 196608 @ 0x10000... 196608 (100 %) Wrote 196608 bytes at 0x10000 in 17.1 seconds (92.1 kbit/s)... Leaving...
and then start blinking!
0 notes