Jump to content

Rickta59

Global Moderators
  • Content Count

    1,123
  • Joined

  • Last visited

  • Days Won

    71

Everything posted by Rickta59

  1. Rickta59

    SD card bootloader - convert assembler to C++?

    So I spent some time with the latest energia 1.8.7E21. It is still using msp430-gcc. That project I linked in the previous post won't work because that code is using the newer msp430-elf-gcc. I did put together an example of using msp430-gcc style code and the blink project above that compiles and create asm only project .. well almost main has to jump to our asm code so there are a couple of instructions to get there. Three files are needed: blink_with_msp430-gcc_asm.ino /* blink_with_msp430-gcc_asm.ino */ /* * we aren't going to use the .ino file */ main.cpp // We override the main function from Energia // and just jump to our __reset_vector__ routine // in blink.S int main() { asm("jmp _reset_vector__"); } blink.S ;------------------------------------------------------------------------------- ; blinkasm.S - gcc compatible interrupt driven led blinker in msp430 asm ; ; Version 1.0 - 10/22/2011 rick@kimballsoftware.com ; Version 1.01 - 7/22/2014 rick@kimballsoftware.com modified for msp430-elf-gcc ; Version 1.02 - 11/02/2014 rick@kimballsoftware.com more changes for msp430-elf-gcc ; $ msp430-elf-gcc blinkasm.S -D_GNU_ASSEMBLER_ -Wall -Os -g \ ; -fdata-sections -ffunction-sections -mmcu=msp430g2553 -T \ ; -T msp430g2553.ld -I/tmp/a/include -L /tmp/a/include/ -nostdlib ; Version 1.03 - 03/16/2019 rick@kimballsoftware.com made compatible with energia ; ;------------------------------------------------------------------------------- .file "blinkasm.S" #include <msp430.h> ;------------------------------------------------------------------------------- ;;; ---- gcc doesn't know about PC,SP,SR,CG1,CG2 ---- #define PC r0 #define SP r1 #define SR r2 ;------------------------------------------------------------------------------- ;;; ---- CONSTANTS ---- //#define TEST_IRQ_OVERHEAD #ifndef TEST_IRQ_OVERHEAD #define _50USEC (50-1) /* @1MHz MCLK results in 50uSec/interrupt */ #define _500MSEC 10000 /* @1MHz MCLK results in 500ms/LED toggle */ #else ;; This test illustrates the minimum CCR0 value that can be used ;; 22 cycles is based on the interrupt overhead #define _50USEC 22 /* @1MHz MCLK results in 23uSec/interrupt */ #define _500MSEC 1 /* @1MHz MCLK results in 23uSec/LED toggle */ #endif #define _LED_PIN BIT6 /* PORT1 pin, Launchpad has BIT0=Red and BIT6=Green */ ;------------------------------------------------------------------------------- ;;; ---- Registers used as globals ---- #define LED_PIN r4 #define TIMER_CYCLES r5 #define INTERVAL_CNT r6 #define CNT r7 ;; or you could use some ram variables .lcomm tcycles,2 ; example use of local bss data variable .lcomm cnt,2 ; example use of local bss data variable ;------------------------------------------------------------------------------- .section .text,"ax",@progbits ;------------------------------------------------------------------------------- .global _reset_vector__ ; it is important to name it "_reset_vector__" ; we prevent the C runtime start code from getting ; linked by using this name _reset_vector__: ;; disable watchdog and set stack to highest RAM addr mov.w #WDTPW|WDTHOLD,&WDTCTL mov.w #__stack,SP ; gcc ldscripts compute __stack based on mmcu ;; initialize clock,gpio,timer init: ;; configure DCO to precalibrated 1MHz clr.b &DCOCTL mov.b &CALBC1_1MHZ,&BCSCTL1 mov.b &CALDCO_1MHZ,&DCOCTL ;; initialize global register values mov.w #_LED_PIN,LED_PIN ; load constant into register constant mov.w #_50USEC,TIMER_CYCLES ; load constant into register constant mov.w #_500MSEC,INTERVAL_CNT ; load constant into register constant mov.w INTERVAL_CNT,CNT ; initialize register based counter ;; initialize GPIO bic.b LED_PIN,&P1OUT ; LED turned off to start bis.b LED_PIN,&P1DIR ; Configure P1.0 as output pin ;; initialize TimerA0 mov.w #CCIE,&TA0CCTL0 ; Enable TA0CCR0 interrupt mov.w TIMER_CYCLES,&TA0CCR0 ; Set TIMER_CYCLES cycles mov.w #TASSEL_2|MC_2,&TACTL ; SMCLK, Continuous Up Mode ;; enable interrupts and loop forever ;; real work done in the CCR0 interrupt nop eint loop: ;; Note: could sleep here instead jmp loop ; cycles:2 ;------------------------------------------------------------------------------- ; TIMER0_A3_ISR - Timer0_A3 CCR0 interrupt handler for vector 0xfff2 ;------------------------------------------------------------------------------- .global __isr_9 ; to insert an interrupt vector into the vector ; table from assembly, we have to use a specific ; naming convention we must call this function ; "__isr_9" this forces it into the 9th vector ; slot counting from 0 starting memory address ; 0xffe0. It is 9 because each vector is ; 2 bytes so we end up in slot 0xfff2 ; all this is because of the way msp430-gcc ; works with interrupts ; .vectors in the msp430g2553/memory.x starts ; @ 0xffe0 ; there are numbered isr_0 ... isr_14 even though ; there are 16 vectors. isr_15 is actually called ; _reset_vector__ you can see how we use it in this ; code. ; see the file: ; http://www.ti.com/lit/ds/symlink/msp430g2553.pdf ; look at the "Interrupt Vector Table" page 11 __isr_9: ;; before we even start running the mcu does a push PC, and a push SR cycles:6 dec.w CNT ; have we looped INTERVAL_CNT times? cycles:1 jnz 1f ; exit if we haven't reached 0 cycles:2 ;; toggle led pin after (INTERVAL * TIMER_CYCLES) has occured xor.b LED_PIN,&P1OUT ; cycles:4 mov.w INTERVAL_CNT,CNT ; reinitialize interval counter cycles:1 1: add.w TIMER_CYCLES,&TA0CCR0 ; set new CCR0 and go again cycles:4 reti ; cycles:5 ; vim: ts=8 sw=8 expandtab: Put those in a new Energia sketch compile it for an msp430g2553 and it should produce output that looks like this: blink_with_msp430-gcc_asm.ino.elf: file format elf32-msp430 Disassembly of section .text: 0000c000 <main>: c000: 03 3c jmp $+8 ;abs 0xc008 c002: 0f 43 clr r15 0000c004 <__ctors_end>: c004: 30 40 5e c0 br #0xc05e 0000c008 <_reset_vector__>: c008: b2 40 80 5a mov #23168, &0x0120 ;#0x5a80 c00c: 20 01 c00e: 31 40 00 04 mov #1024, r1 ;#0x0400 0000c012 <init>: c012: c2 43 56 00 mov.b #0, &0x0056 ;r3 As==00 c016: d2 42 ff 10 mov.b &0x10ff,&0x0057 c01a: 57 00 c01c: d2 42 fe 10 mov.b &0x10fe,&0x0056 c020: 56 00 c022: 34 40 40 00 mov #64, r4 ;#0x0040 c026: 35 40 31 00 mov #49, r5 ;#0x0031 c02a: 36 40 10 27 mov #10000, r6 ;#0x2710 c02e: 07 46 mov r6, r7 c030: c2 c4 21 00 bic.b r4, &0x0021 c034: c2 d4 22 00 bis.b r4, &0x0022 c038: b2 40 10 00 mov #16, &0x0162 ;#0x0010 c03c: 62 01 c03e: 82 45 72 01 mov r5, &0x0172 c042: b2 40 20 02 mov #544, &0x0160 ;#0x0220 c046: 60 01 c048: 03 43 nop c04a: 32 d2 eint 0000c04c <loop>: c04c: ff 3f jmp $+0 ;abs 0xc04c 0000c04e <__isr_9>: c04e: 17 83 dec r7 c050: 03 20 jnz $+8 ;abs 0xc058 c052: c2 e4 21 00 xor.b r4, &0x0021 c056: 07 46 mov r6, r7 c058: 82 55 72 01 add r5, &0x0172 c05c: 00 13 reti 0000c05e <_unexpected_>: c05e: 00 13 reti Disassembly of section .vectors: 0000ffe0 <__ivtbl_16>: ffe0: 04 c0 04 c0 04 c0 04 c0 04 c0 04 c0 04 c0 04 c0 ................ fff0: 04 c0 4e c0 04 c0 04 c0 04 c0 04 c0 04 c0 08 c0 ..N............. To get your SD Card Bootloader running in Energia you would have to replace the blink.S with SDBSL-G2553.S and change your coding style to make msp430-gcc happy. You would also have to replicate all the code that the normal C runtime code does to create an environment for a C++ application. Basically you have to setup the .data section (copying the initial values from flash to ram), initialize the .bss section all to zero, loop through all the global c++ constructors, then call the users main function. blink_with_msp430_asm.zip
  2. Rickta59

    SD card bootloader - convert assembler to C++?

    Interesting stuff. Here are some things that seem like they might cause you issues: Rewriting in C++ can be small. Using the Energia API will defeat that and not result in a 1k sd card bootloader. Cross Platform issues, Energia supports Windows, OS/X, and Linux. You need to supply the binaries for all the tools you are using that run on all platforms. It is easiest to stick with the gcc object tools for manipulating the .hex file. Naken asm source - No one has that so you either provide the naken assembler binary. Alternatively, if you want to just go with assembler + Energia, you might rewrite your asm code so that it is compatible with msp430-gcc assembly. I think Energia still takes .S files (gcc assembler source) The biggest difference between naken and gcc is having an external linker script for the symbol addresses you have hard coded in the .m43 source code. You are facing the same kinds of issues I bumped up against doing a small GDB bootloader. However, I was trying to avoid being part of the user code or changing the way Energia sets up the linker scripts. I'm not sure you can overcome that without getting into the details of the vector table and the linker script. You might find this useful: https://gist.github.com/RickKimball/ead0b3b0f28f0dbf426c51f46ced59ab
  3. Rickta59

    Add MSP432 support to Arduino?

    not json but instructions given for linux https://github.com/RickKimball/tivac-core Assumes you have openocd and arm-none-eabi-gcc in your path. Probably won't work for windows. Probably will work for OSX.
  4. Those APA-102 leds that are packaged like ws281x pixels but you drive like a ws2801 (clk/data) have hit ebay.com. I ordered a 1 meter length and it arrived today. They look and feel like a ws2811 strip. It has 4 connections. 5V, GND, CLK, DATA. I whipped up a quick test and they seem to be happy: /** * APA-102 - test of 5 leds * * Author: rick@kimballsoftware.com * Date: 09-11-2014 * */ #include <fabooh.h> #include <main.h> #include <spi.h> namespace { typedef spi_attr_t<> SPI_MODE3_A; typedef spi_eusci_b0_t<CS, SCLK, MOSI, NO_PIN, SPI_MODE3_A > spi_t; spi_t spi; } void setup(void) { spi.begin(); spi.set_divisor(8); // 1MHz spi } static const unsigned char buff0[] = { 0x00, 0x00, 0x00, 0x00, // start frame (0b111 << 5 | 31), 0x00, 0x00, 0xFF, // red (0b111 << 5 | 31), 0x00, 0xFF, 0x00, // green (0b111 << 5 | 31), 0xFF, 0x00, 0x00, // blue (0b111 << 5 | 31), 0xFF, 0xFF, 0xFE, // white (0b111 << 5 | 31), 0x00, 0x00, 0x00, // off 0xFF, 0xFF, 0xFF, 0xFF // end frame }; static const unsigned char buff1[] = { 0x00, 0x00, 0x00, 0x00, // start frame (0b111 << 5 | 31), 0x00, 0x00, 0x00, (0b111 << 5 | 31), 0x00, 0x00, 0x00, (0b111 << 5 | 31), 0x00, 0x00, 0x00, (0b111 << 5 | 31), 0x00, 0x00, 0x00, (0b111 << 5 | 31), 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF // end frame }; void loop(void) { while(1) { spi.select(); spi.shiftout(buff0, sizeof(buff0)); spi.deselect(); delay(1000); spi.select(); spi.shiftout(buff1, sizeof(buff1)); spi.deselect(); delay(1000); } } These chips are perfect when you don't want to run your msp430 at high clock speed but still want to be able to use a bunch of rgb leds without resorting to external led drivers or shift registers. However, if you do want to run fast, even faster than the ws281x 800kHz, you can. I tested with both a low speed (500Hz) and a high speed (up to 16MHz) configuration successfully. Using an msp430fr5969 chip at 8MHz I settled on 1MHz in the code above. For a nice review of the chip's internals, you can read more about them on this cpldcpu's blog: http://cpldcpu.wordpress.com/2014/08/27/apa102/ -rick
  5. Rickta59

    Store values inside µc

    The msp430g2231 only has a total of 2048 bytes of flash. If you use Energia, you are going to suck up half that flash just getting it to compile an empty sketch. The EEPROM on an atmega328p has 1024 bytes of eeprom. What do you want to store in EEPROM?
  6. Rickta59

    The problem about compiling "Blink" by Energia

    this was fixed a long time ago. https://github.com/robertinant/EnergiaNG/issues/10 are you sure you have the latest stuff?
  7. googling seems to indicate this is a known problem.
  8. Rickta59

    CoRTOS: An open source minimalist RTOS

    It is deleted
  9. Rickta59

    CoRTOS: An open source minimalist RTOS

    Do you want people to help you with this? It seems like you are expecting people to fill in the gaps. Should I just delete the repo?
  10. Rickta59

    CoRTOS: An open source minimalist RTOS

    I uploaded the zip file that is available from sourceforge. You pointed me at that. If I'm going to upload something to source control, I'm going to base it on a source code control system instead of a forum post that is likely to disappear. No I don't think it is presumptous. I really don't claim to have written it. The readme doesn't say anything about me being the author. The README.md indicates it is a mirror of your original. It also has all your contact information not mine. I would much prefer that you have a repository that I could fork and provide changes via a pull requests instead of dealing with zip files. Zip files are not a source code control system.
  11. Rickta59

    CoRTOS: An open source minimalist RTOS

    I created a mirror of your source code on github. I extracted all the files so people can look at it without downloading a zip file. I also created a msp430 branch that shows the changes I needed to make to get simple blinky and super blinky to compiler for the msp430. https://github.com/RickKimball/CoRTOS/tree/msp430 -rick
  12. Rickta59

    CoRTOS: An open source minimalist RTOS

    Thanks I hadn't found that in my searches. Do you plan on doing any msp430 specific features?
  13. Rickta59

    CoRTOS: An open source minimalist RTOS

    Sure I understand that. I'm just passing along my biased observations What I've seen with the msp430 and RTOS support in general is this. People/groups make a simplistic stab at supporting the msp430 and then just as quickly abandon the effort. It is hard to compete with the fully featured TI-RTOS/SYS-BIOS code. TI-RTOS is free with a BSD license. TI actually supports it on their e2e.ti.com forum. However, it is a beast. TI-RTOS tames you, you don't tame it. I've heard it is slow and bloated on the msp430. It uses an arcane set of TI custom command line based tools that force you to conform. I don't want to be tamed. In my opinion, TI is good with hardware and software is an afterthought that some marketing guy needs to be able to check boxes on a specification sheet. I think there is a niche for a small and simple RTOS, not unlike what you have posted, that actually fully takes advantage of the lower power features of the msp430 chips. However, it would be easier to pass on fixes and identify real software issues if you put the source code on some public repository. That is assuming your goal is to get a group of people actively using the code. It might eliminate the muttering of 100 people making the same fix in some snapshot in time of a zip file you randomly post on various web forums. Other users here have posted some simple tasking code. However, there is always some catch or no followup. This guy posted some promising code. Sadly it was writtten to work only with the $1500 IAR compiler and after he posted it there wasn't any follow up. FreeRTOS supposedly works on the msp430 chips. So don't think I'm discouraging your efforts. I applaud it. Seems like a good first start. If you want feedback, I'll provide it.
  14. Rickta59

    Serial Port Problem

    I'm not actually not a moderator any more .. not sure why it is still attached to my userid. @bluehash ?
  15. Rickta59

    Serial Port Problem

    I'm not sure why you are posting on a thread about the msp430g2553. You should start another thread and title it "Serial Problem with CC3200"
  16. Rickta59

    Serial Port Problem

    I have no clue. I don't see any msp430g2553 in there.
  17. Rickta59

    Supported MSP430's

    Looks great. I did one https://oshpark.com/profiles/Rickta59 that didn't have any of the required passives. Mine was lame compared to yours. Also it is the only PCB I've ever designed. I decided I'd leave it to others to do properly. Is your PCB design something you would be willing to share?
  18. Rickta59

    Serial Port Problem

    With the G2 launchpad, the best thing to do is remove the TX/RX jumper pins and use an external dongle. USB dongles used to be expensive however you can get them now for less than $2. Pick one that uses 3v3 signals or you will fry your launchpad chip. Something like this will solve all your problems ($1.69 free shipping * at least in the US): https://www.ebay.com/itm/272758761169 Just connect GND/TX/RX to your launchpad leave the 5v power unconnected (maybe even tape it back to the wire so you don't forget) As an added bonus, you will no longer be limited to 9600 baud. I've run these pl2303 chips with an msp430g2553 at 230k without a problem. These show up as /dev/ttyUSBx on linux. -rick
  19. Rickta59

    CoRTOS: An open source minimalist RTOS

    Some general first impressions about CoRTOS: I can spell yield() but I have to ask merriam-webster how to spell relinquish() <msp430.h> would allow people to use whichever MCU they select in CCS without having to edit the source files #include <stdint.h> is a better way to grab uint8_t and friends #include <stdbool.h> is a better way to grab true, false and bool GPL isn't the best license for RTOS code. Even the TI-RTOS (SYS/BIOS) is BSD. FreeRTOS is MIT. nuttx is BSD. RIOT is LPGL. mbed-rtos is MIT. it would be nice if the code would compile with both msp430-elf-gcc and the TI cl430 compiler. inline asm is easier with msp430-elf-gcc and would match your other platforms Although I haven't tried, it doesn't seem like this code would work properly with large model code (where registers are 20 bits instead of 16 bits) look at switching to uintptr_t and intptr_t . uintptr_t is either int16 or _int20 depending on the compiler mode selected. (this would help with 32bit stuff too uintptr_t is uint32_t there) MSP430s have extensive low power features. It isn't just one sleep mode. These modes rely on the SR being properly saved and restored, not sure how this fits into the tasking code. Look into using LPM1, LPM3, etc... using uint8_t results in slower code on an msp430 when you are really just trying to use a natural integer. A locally declared uint8_t is still going to use 2 bytes on the stack. UpperAndLowerCaseIsTediousToReadAndTediousToTypeAndRememberWhenToSwitchCase -rick
  20. Rickta59

    CoRTOS: An open source minimalist RTOS

    Still an issue with upper / lower case naming conflicts: diff -r ./fixed/CoRTOSmessage.c ../../Downloads/cortos_d1/CoRTOSmessage.c 18c18 < #include "CoRTOSuP.h" --- > #include "CoRTOSup.h" the file is named 'CoRTOSuP.h' the code uses 'CoRTOSup.h'
  21. Rickta59

    CoRTOS: An open source minimalist RTOS

    You seem to misunderstand Energia. It is based on the Arduino IDE source code (java based), with customized c++ cores that work with a variety of different TI processors. The msp430, arm cortex, and C2xxxx are all represented. There is no interpreted mcu code, it is C/C++ source that implements the Arduino API. It gets compiled using a cross compiler appropriate for the architecture selected (msp430-gcc, arm-none-eabi-gcc etc) and runs on Windows, Mac, and linux. The TI RTOS (previously called SYSBIOS) has been available for a long time and is fully documented. http://www.ti.com/tool/TI-RTOS Energia implements the TI RTOS in a novel way. You create tasks by creating a new tab in the Energia IDE that contain a setup() and loop() for each task. It automatically uses those tabs to start the tasks. However, that is just skimming the surface. See more info here http://energia.nu/guide/multitasking/ Granted the multitasking implementation hasn't been done for the msp430 chip, however it would be possible. -rick
  22. Rickta59

    CoRTOS: An open source minimalist RTOS

    Interesting chunk of code, however it doesn't seem like you've invested much effort in your msp430 port or cross platform compatibility. The code only seems to attempt only one msp430 mcu (msp430fr6989). As there is no project file for CCS or a makefile, I created an empty CCS project using the TI C compiler for an msp430fr6989. I imported the CoRTOSblinkyMSP.c source and all the headers. It has a bunch of obvious errors. Have you tried to compile that file? It doesn't compile, at least with CCS 7 on ubuntu. Hint 1: you can't use msp430-elf-gcc Hint 2: Edit CoRTOSuP.h and make the processor uP_MSP430 the default Hint 3: Don't try this on a files system that is case sensitive. The source code and files provided uses a mix of upper and lower case. You need to fix the incorrect file name references or rename the files to match the names. First batch of errors: Description Resource Path Location Type #150 variable "task_stack_size" has already been initialized CoRTOStask.c /cortos line 33 C/C++ Problem .. defined multiple times in the source #1965 cannot open source file "msp430FR6989.h" CoRTOSkernel.c /cortos line 18 C/C++ Problem needs to be msp430fr6989.h" .. probably should be just <msp430.h> #20 identifier "t" is undefined CoRTOSblinkyMSP.c /cortos/apps line 202 C/C++ Problem I don't see this declared anywhere, I'm assuming you meant "n" not "t" #20 identifier "tn" is undefined CoRTOSblinkyMSP.c /cortos/apps line 208 C/C++ Problem not sure what you meant to pass to resume_task() .. guessing it is also "n" ? After I addressed those problems, I changed the code around so I could run it on an msp430fr5969 launchpad. The release build results in a multi-tasking blinky app that uses about 1k of code and 200 bytes of ram. That seems to work, maybe I'll try a little more tomorrow. -rick
  23. Rickta59

    CoRTOS: An open source minimalist RTOS

    What does this offer over the RTOS in energia?
  24. Did you try pulling the jumpers for the UART on your launchpad? On linux, the msp430g2553 is notorious for causing hangs because of the Virtual COM port of the MSP-EXP430G2. I can get around the problem by removing the UART jumpers and using an external 3V3 USB serial dongle.
  25. Rickta59

    An extra USB for MSP430

    If the usb is really a keyboard interface you could get one of those usb to ps/2 dongles.
×