Welcome, Guest
You have to register before you can post on our site.



Search Forums

(Advanced Search)

Forum Statistics
» Members: 1,003
» Latest member: wbicaxias
» Forum threads: 859
» Forum posts: 5,100

Full Statistics

Latest Threads
Suggestions future releas...
Forum: EmBitz IDE
Last Post: bufran
Yesterday, 06:39 AM
» Replies: 137
» Views: 73,575
Does EmBitz support Nucle...
Forum: EmBitz IDE
Last Post: Lutz Kämmerling
17-02-2019, 10:35 PM
» Replies: 0
» Views: 29
loading to device without...
Forum: EmBitz IDE
Last Post: escalator
08-02-2019, 04:54 PM
» Replies: 18
» Views: 9,971
Introducing section withi...
Forum: ArmGCC - EmBlocks
Last Post: PDonchev
22-01-2019, 08:58 PM
» Replies: 1
» Views: 426
Kinetis MK66 & SVD
Forum: SVD (System view) files
Last Post: Workalot
16-12-2018, 04:39 AM
» Replies: 1
» Views: 470
Download/Debugging Silabs...
Forum: Debug interface scripting
Last Post: Polarisru
10-12-2018, 01:38 PM
» Replies: 4
» Views: 1,617
Burning flash and debuggi...
Forum: Debug interface scripting
Last Post: Polarisru
10-12-2018, 01:33 PM
» Replies: 0
» Views: 236
Embitz with GCC-ARM
Forum: ArmGCC - EmBlocks
Last Post: Tony201800
30-11-2018, 12:01 AM
» Replies: 0
» Views: 365
emBitz, MK66, Debugger an...
Forum: EmBitz IDE
Last Post: Workalot
27-11-2018, 10:40 AM
» Replies: 1
» Views: 422
EBLINK: STM32L496ZG not s...
Forum: Debug interface scripting
Last Post: vargham
22-11-2018, 09:36 AM
» Replies: 1
» Views: 604

  The case for CAN
Posted by: smitjs - 01-09-2018, 11:27 AM - Forum: General - Replies (3)

I have been working on various new machines, planters, fire engines, etc for years.
There never was any question, distributed computing was always used. At first 8085 types, then Atmel 328 was used, mainly due to the avalability of Arduino Nano boards and WinAVR.
The AVR does work, but debugging is sadly lacking. I have also used Raspi, and was disgusted with the bootup sequence. That is totally out of the question.
Why use such a horrible operating system on any machine? Nobody wants to wait that long for any machine to start working.
ARM boards became available, and I switched to STM32F103 initially, using Embitz. What a marvellous upgrade! Embitz and the EBmoitor is absolutely marvellous!
Why struggle with AVR? The STM32 units are cheap enough.
The first consideration then is what interconnection type to use between units.
I did use serial in the form of RS485. All micros I used have serial, and it is always easy to add another bit bang one. The problem with a RS485 setup is that it is a master - slave setup.
For fast response, the master has to poll often, resulting in micros spending time looking at serial, while neglecting its real work.
The STM32 units can receive serial without using processor time, but the problem of fast transmit response remain. DMA does not do it for short massages.
I have used Ethernet with the Raspis, disasterly. Those sockets are simply horrible in a moving and shaking machine.
Essentially, any master slave setup is not the best. It has to be multimaster, minimum wiring, and no collisions.
No wonder canbus is used so widely. It is really the answer.
It appears all the STM32 units has the provision for Canbus. It is easily applied, does not use processor time for receiving, and has numerous filters to block any unwanted messages.
To use the full Canbus specs, driver chips must be used, but canbus can even be used without that. See Siemens Appnote AP2921. Their one wire setup can  be extended simply by using LM393 comparators and higher voltage on the one wire. That will be the cheapest setup for longer connections.
Canbus will transmit when the bus becomes free, the processor only posts the txmessage.
Received messages are filtered and stored, the processor reads the messages when there is time available, no interrupts are required, and no unnecessary messages are received.
The filters only pass messages intended for the particular unit.
The initial code for a STM32F407 is
 //p1099 CAN master control register Page numbers refer to the STM32F407 reference manual
  CAN1->MCR &= (~(uint32_t)CAN_MCR_SLEEP); //wake up from sleep mode
  CAN1->MCR = (CAN_MCR_INRQ);       //p1083 init mode, disable auto retransmission//CAN_MCR_NART |
  uitime = uimillis + 500;
  while(!(CAN1->MSR & CAN_MSR_INAK)){assert(uimillis, <, uitime);} //p1083 wait for confirmation
Set up the baudrate

  //A good rule of thumb is to have your sampling point at 70-80% of the nominal bit time.
  //p1095 For 125Khz CAN: APB1 42Mhz;(APB1 clocked at 42 MHz)
  // quanta 1+9+4 = 14, 14 * 24 = 336, 42000000 / 336 = 125000
  // CAN Baudrate = 125Kbps (CAN clocked at 42 MHz) Prescale = 24

  CAN1->BTR  = 0x01 << 24; //p1108 CAN bit timing register  Resynchronization jump width
  CAN1->BTR |= 0x03 << 20; //TS2 tBS2 = tq x (TS2[2:0] + 1)p1108
  CAN1->BTR |= 0x08 << 16; //TS1 tBS1 = tq x (TS1[3:0] + 1)p1109
  CAN1->BTR |= 0x17;       //prescaler 24 p1109
  CAN1->FMR  = 0x0E << 8;   //p1116 CAN filter master register
This must be changed to the required speed and APB1 clock speed
Set up the receive filters

  CAN1->FMR  = 0x0E << 8;   //p1116 CAN filter master register
  CAN1->FMR |= 1;          //p1116 Initialization mode for the filters.
  CAN1->FM1R = 0;          //p1117 Filter mode register 1:32bit filters mask mode
  CAN1->FS1R  = 0x0FFFFFFF;//p1117 Single 32-bit scale configuration
  CAN1->FFA1R = 0x00000000;//p1118 Fifo assignment register
  CAN1->sFilterRegister[0].FR1 = 0x00B << 21;//p1091,1119 COMP
  CAN1->sFilterRegister[1].FR1 = 0x00D << 21;//p1091,1119 COMP
  CAN1->sFilterRegister[0].FR2 = 0x47F << 21;//p1091,1119 MASK
  CAN1->sFilterRegister[1].FR2 = 0x47F << 21;//p1091,1119 MASK
  CAN1->FA1R  = 0x00000001;//p1118 filter activation register filters 0 only
  CAN1->FMR   = 0x0E << 8; //p1116 CAN filter master register clear init bit
  CAN1->MCR &= ~(CAN_MCR_INRQ);// p1083 normal mode
  uitime = uimillis + 500;
  while(CAN1->MSR & CAN_MSR_INAK){assert(uimillis, <, uitime);};  //p1083 wait for confirmation

Set up a tx message struct

typedef struct
{ u16   id;                 // 11 bit identifier
  u8    data[8];            // Data field
  u8    len;                // Length of data field in bytes
  u8    format;             // 0 - STANDARD, 1- EXTENDED IDENTIFIER
  u8    type;               // 0 - DATA FRAME, 1 - REMOTE FRAME
canmsg cantxmsg;

I found that most messages used were the 11bit id only, or id + 1. The full 8 bytes data was rarely used.
The transmit code:

  while(!(CAN1->TSR & (1 << 26)))//p1103 TME0 Mailbox empty
  {assert(uimillis, <, uitime);} //NAK?
  CAN1->sTxMailBox[0].TIR = 0;                     //p1110
  CAN1->sTxMailBox[0].TIR |= (txmsg->id << 21)|txmsg->type;
  CAN1->sTxMailBox[0].TDTR = (txmsg->len & 0x07);    //p1111
  if(0 == txmsg->len)
 { CAN1->sTxMailBox[0].TDLR = (txmsg->data[0]);
 }else if(1 == txmsg->len)
  { CAN1->sTxMailBox[0].TDLR = ((txmsg->data[1] << 8) |  (txmsg->data[0]));
  { CAN1->sTxMailBox[0].TDHR = ((txmsg->data[7] << 24) //p1112
                                 |(txmsg->data[6] << 16)
                                 |(txmsg->data[5] <<  8)
    CAN1->sTxMailBox[0].TDLR = ((txmsg->data[3] << 24)
                                 |(txmsg->data[2] << 16)
                                 |(txmsg->data[1] <<  8)
  CAN1->sTxMailBox[0].TIR |= 0x01; //p1110 TXRQ

Receive is:

volatile u32 mail0 = 0;
    rxid = (((CAN1->sFIFOMailBox[0].RIR) >> 21) & 0x07ff);  //p1113 11 bits only (If you require the id in your code)
    datalen = (CAN1->sFIFOMailBox[0].RDTR) & 0x0F; //p1114
    //else if 0 datalen simply read CAN1->sFIFOMailBox[0].RIR
     mail0 = CAN1->sFIFOMailBox[0].RDLR;
      rxdata[0] = (mail0 & 0xFF);
      mail0 >>= 8;
      rxdata[1] = (mail0 & 0xFF);
      mail0 >>= 8;
      rxdata[2] = (mail0 & 0xFF);//p1115
      mail0 >>= 8;
      rxdata[3] = (mail0 & 0xFF);////p1115
      mail0 = CAN1->sFIFOMailBox[0].RDHR;
       rxdata[4] = (mail0 & 0xFF);////p1115
       mail0 >>= 8;
       rxdata[5] = (mail0 & 0xFF);////p1115
       mail0 >>= 8;
       rxdata[6] = (mail0 & 0xFF);////p1115
       mail0 >>= 8;
       rxdata[7] = (mail0 & 0xFF);//p1115
 Change as you like
The filters are not easy to envisage, but can easily be proven by this code:

  #define COMP 0x00D //change as required
  #define MASK 0x47F  //change as required
  u16 id= 0;
     for(id=0; id < 0x800; id++)
        {// printf("%d ",id);
            if ((id & MASK) == COMP)
           { printf("0x%03X\n", id);
Canbus is also easily tested in logic analysers.
I am not aware of anything that can beat canbus for interconnection.
I hope this post is of help to somebody.
Johan Smit

Print this item

  does Embitz have watchpoints
Posted by: jheissjr - 15-08-2018, 02:18 PM - Forum: EmBitz IDE - Replies (4)

I saw a tutorial on Mcuoneclipse.com discussing watchpoints in Eclipse and CDT. I have used them and they come in handy at times. Does EmBitz have watchpoints?


Print this item

  Find function declaration with custom Makefile
Posted by: Konami - 14-08-2018, 01:58 PM - Forum: EmBitz IDE - No Replies

I'm using a custom Makefile to build my EmBitz project so that the code can be portable between systems and doesn't require an IDE to simply build. However, the EmBitz is unable to find the declarations of any of my functions from included libraries. I added the directories to the Additional Search Paths in C/C++ Parser Options but I'm guessing it should be going somewhere else.

Print this item

  Semihosting error - alignment issue
Posted by: splin - 13-08-2018, 10:34 PM - Forum: ArmGCC - EmBlocks - Replies (1)

I have found a problem with semihosting which seems to be caused by an odd byte aligned string in initialise_monitor_handles.

Board: STM32F407VG Discovery

I was having erratic results with semihosting - somtimes it worked, sometimes it didn't. I created a project using the wizard, enabled semihosting, no standard peripheral library. I managed to reduced the code to a minimum which illustrates the problem:

#include "stm32f4xx.h"
#include <stdio.h>
#include <errno.h>
int i=0, j=0 ,k;

int main(void)
    i = printf("\fBegin\n");
    j = errno;

Nothing is output on the console. Interestingly the first printf() returns 7 which is correct but errno is 22 - EINVAL

Now change the last printf to "Done123\n" and it seems to work - ie. the output appears on the console, but now printf() returns -1 and errno is 0! "Done1234\n" also works as does "Done1234567\n" but "Done12345\n" doesn't.

Investigating further, the problem comes from the constant strings in the rodata part of main.o containing the path name passed to the SYS_OPEN() call via BKPT 0xAB at the start of initialise_monitor_handles() when populating the file descriptor tables. The path string is ":tt" which is used to get the file handles for stdin, stdout and stderr from the gdbserver. When semihosting fails, this string is located at an odd byte address and SYS_OPEN() returns -1 for the stdin FD handle. From the map file:

                0x200019bf        0x4 d:/development/tools/embitz/1.11/share/em_armgcc/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/lib/armv7e-m/fpu\librdimon_n.a(rdimon-syscalls.o)
 *fill*         0x200019c3        0x1 

(I am executing from RAM and relocating the vector table to 0x20000000)

Adding '3' to the last printf 16 bit word aligns the ":tt" string and the SYS_OPEN() call suceeds.

So it appears there are two errors - 1) the gdbserver can't handle the path string not being word aligned, and 2) the returns from printf() and errno are wrong. Interestingly when the file handle table is incorrectly setup due to the odd alignment of the path string, printf() eventually calls SYS_WRITEC() via BKPT 0xAB (ouptut a single character) but when semihosting appears to work SYS_WRITE0() is invoked to output the whole string.

Hope there is enough there to resolve the problem. I don't have source to rdimon or newlib so I diagosed the above by stepping through the assembler. I have attached the project.

Attached Files
.zip   Semihosting.zip (Size: 119.91 KB / Downloads: 44)
Print this item

  edit cursor vanishes on return from debug
Posted by: escalator - 10-08-2018, 08:56 PM - Forum: EmBitz IDE - No Replies

a very minor annoyance: when reverting to edit view from debug view the cursor  vanishes, requiring a re-click on the current edit location.
and while we're at minor annoyances, here is a curiosity (in edit mode):
Keep up the good work,

Print this item

  How to create stm32l476 project step by step?
Posted by: Jaguar_showjumping - 07-08-2018, 04:13 PM - Forum: EmBitz IDE - Replies (2)

Hi, everybody!
Could you help me?
I like embitz and use it with stm32f4 and stm32l0.
Now  I need stm32l476 MCU. But I didn't understand how to get it work.
I use only cmsis. Don't like Std P.lib and HAL.

How to create stm32l476 project step by step?
For the first time I got stm32l476-disco board. But in the future I prefer load programs via SWD (stlink) directly into my pcbs

Print this item

  STM32F4 atan2
Posted by: smitjs - 06-08-2018, 05:41 AM - Forum: EmBitz IDE - Replies (3)

I am using STM32F407VGT6 with Embitz.
The board contains an accelerometer, which I have successfully used previously with a STM32F103.
Calculation of the roll and pitch requires the function atan2.
On the STM32F4 I get "undefined reference to `atan2'"
I have included <math.h>
Any help greatly appreciated
Thank you
Johan Smit

Print this item

  STM32F107 support?
Posted by: hoffa444 - 04-08-2018, 04:20 PM - Forum: ArmGCC - EmBlocks - No Replies


When following the wizard and selecting a STM32F107, and compiling a "blank" main.c you get errors.
There seems f.i. be file naming errors from the result of the wizard.

Is there really support for this CPU?

best regards Hoffa

Print this item

  EBLINK: STM32L496ZG not supported
Posted by: vierling - 27-07-2018, 07:58 AM - Forum: Debug interface scripting - Replies (1)

Call: eblink -I ST-link -D stm32-auto -G

EB-link by Gerard Zagema __ALPHA__ Jul 11 2017 08:57:24.

Interface: ST-link
Interface at 1:7 - <BUS>:<ADDR>
Interface type: STlink/V2-1
STmicro device ID: 0x461

Error: Unknown device ID
       Please report this ID so that we can add it.

Hi, this is what I want to ask: Can you add this target?
I guess, new entries in "stm32l4x.script".
(the target is a Nucleo-144 STM32L496)


Print this item

  IDE editor preferences saving/loading
Posted by: Stadstot - 09-07-2018, 04:27 AM - Forum: EmBitz IDE - Replies (1)

Is there some mechanism for saving and restoring my customized IDE settings like highlightings and colors, keybindings, foldings and other editors preferences to file or files?
I found some files in appdata/roaming/embitz, but not all settings and all profiles in same file, which is pretty inconvenient if I want to work on someone else's computer.

Print this item