Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 09:38 29 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : ArmiteH7 crashes

Author Message
HardingJohn

Regular Member

Joined: 28/07/2017
Location: Australia
Posts: 78
Posted: 10:23am 23 Mar 2023
Copy link to clipboard 
Print this post

I think I've got to a bottleneck with ARMmiteH7 5.07.00b11
I think its related to SPI read.

I currently read data every second on SPI3 from an ATME90 3phase AC measurement chip then I write on SPI1 to a Wiznet 5500 chip to display the data on an already established upgraded Websocket on my browser every second.
I also login into an online MQTT server and subscribe.
The data from the 3 phase measurement chip is published to the MQTT server every minute on the Wiznet 5500 chip and as I have already subscribed I get it back OK from the server via the Wiznet 5500 chip.

Everything works fine for days on end.

I also have a Modbus terminal running in the same javascript on my browser that displays the AC measurments. This sends data back from the web page on the websocket when ever I enter it (write or read registers), but causes a major bottleneck in the MMbasic program (print statements to the terminal just about halt) and attempting to run anymore subroutines initiated by the returned data just causes a complete CPU crash.
If only a few more lines of code is run in the loop, after the SPI read, it will struggle on until another SPI read occurs which then crashes the CPU.  It makes no difference what extra code I run.

There appears to be a correlation between the amount of code running in the loop and the ability to  SPI read. Memory is fine. It's not related to SPI speed, or how many SPI reads or writes occur in a set time period. Its not a code error and its not the Wiznet 5500 chip doing it.


Flash:
183K (35%) Program (8794 lines)
  1K ( 0%) 1 Saved Variable (652 bytes)
328K (65%) Free

RAM:
289K (51%) 510 Variables
  2K ( 0%) General
271K (49%) Free

Can anyone shed any light on why this would happen?
Just know enough to get me in trouble, but not quite enough to get me out.
 
HardingJohn

Regular Member

Joined: 28/07/2017
Location: Australia
Posts: 78
Posted: 11:24pm 23 Mar 2023
Copy link to clipboard 
Print this post

This is the last bit of code that might have something to do with the CPU crash that occurs during the first few lines of the next subroutine, or sometimes it survives then crashes at the next SPI read.  The problem relates to how many SPI reads are done regardless of which SPI 1, 2 or 3 and the amount of code, not loop time, that is run.  Run less code and it survives, run more code and it crashes. Run less SPI reads, it survives, run more SPI reads, it crashes.

sub WebSocketRXBinary() 'server receives binary array from client
     RXSockRead% = 1
     Paylength% = 0
     if SockRXBuffer%(1) = 130 then 'only process data if FIN bit set, OPCODE 0001 for binary
       select case SockRXBuffer%(2)-128  'remove the MSB mask bit as it is always set to 1
       case <=125
         Paylength% = SockRXBuffer%(2) - 128 'paylength less MSB mask bit always set to 1
         b% = 6
       case 126
         Paylength% = SockRXBuffer%(3) << 8 or SockRXBuffer%(4)
         b% = 8
       case 127
         Paylength% = SockRXBuffer%(3)<<56 or SockRXBuffer%(4)<<48 or SockRXBuffer%(5)<<40 or SockRXBuffer%(6)<<32 or SockRXBuffer%(7)<<24 or SockRXBuffer%(8)<<16 or SockRXBuffer%(9)<<8 or SockRXBuffer%(10)
         b% = 14
       end select
       for a% = 1 to 4
         MaskKey%(a%) = SockRXBuffer%(a% + b% - 4)
       next a%
       c% = 1
       d% = 1
       for a% = 1 to Paylength% step 2
         RXArrayBuffer%(d%) = (SockRXBuffer%(a% + b% + 1) xor MaskKey%(c%+1))<<8 or (SockRXBuffer%(a% + b%) xor MaskKey%(c%))'unmask all big endian binary data into 16bit values
         d% = d% + 1
         c% = c% + 2
         if c% = 5 then c% = 1
       next a%
       print "Valid Websocket Data Received"
       ProcessRXBinary()
     end if
end sub


This bit of code reads the incoming data SockRXBuffer%() - 8 bits from the already established Websocket (upgraded port 80 web page) created using one of the 8 sockets on the Wiznet 5500 chip on SPI1.  Its output is RXArrayBuffer%() 16 bits. The Websocket array buffer running in javascript is 512 bytes with 8 bytes of header added by the browser.  This gives me 156 x 16 bit registers that I use to create a Modbus over Websocket terminal and 100 x 16 bit binary data for updating values in the webpage.

Websockets are a great way to produce highly interactive web pages as once the web page is drawn via HTML, it is then upgraded to a Websocket allowing high speed bidirectional data (Binary or ASCII) between javascript running in the web page and the MMBasic program running on the ARMmiteH7.
Just know enough to get me in trouble, but not quite enough to get me out.
 
HardingJohn

Regular Member

Joined: 28/07/2017
Location: Australia
Posts: 78
Posted: 04:03am 24 Mar 2023
Copy link to clipboard 
Print this post

When the CPU locks up, a Control C won't restart it, only a power reset or Watchdog timeout will.  All RAM storage is lost, but flash is OK.
It looks like it just runs out of RAM or something when running an SPI Read of only 520 Bytes.
Just know enough to get me in trouble, but not quite enough to get me out.
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 926
Posted: 05:35am 24 Mar 2023
Copy link to clipboard 
Print this post

John

Just out of curiosity are you monitoring any text on your CONSOLE port?

0A47
 
HardingJohn

Regular Member

Joined: 28/07/2017
Location: Australia
Posts: 78
Posted: 10:47pm 24 Mar 2023
Copy link to clipboard 
Print this post

Yes, the console text pauses and then continues if the CPU makes it past the bottleneck. Everything then works OK with no further pauses. If however too much code is executed after the SPI read the CPU just locks up and everything in RAM is lost. Then sometimes the next SPI read crashes the CPU after the console test pause. It depends on the amount of code running after the SPI read that caused the pause in the first place.

Do you think it has something to do with MMbasic limitations on print statement during SPI reads.

If I run the same program on an older STM32H743ZI ver Y (same chip as Nucleo 743ZI board ) overclocked from 400 to 450 MHz using ARMmite 5.05.11, the CPU crashes much earlier when the SPI1 reads the Websock upgrade returning from the Browser.

The newer STM32H743ZI2 ver V chip running at 480 MHz with ARMmite 5.07.0b1 is obviously able to handle a lot more code running before the bottleneck and crash.

Remember SPI3 is reading data from an AC measurement chip every second and SPI1 and the Wiznet 5500 chip is writing (publishing) and reading data back (subscribed) to an online MQTT broker and data is being written via SPI1 and the Wiznet 5500 chip every second to update the webpage which all runs faultlessly on the newer ver V with the faster MMbasic.
If I stop the code running for the LoRa wireless chip on SPI2 to free up resources I can get everything to work fine after squeezing through the bottleneck pause seen on the console text during the first SPI read caused by a Modbus request from the Modbus terminal running in JavaScript on the webpage, and then it runs fine without anymore bottlenecks.
I also have an ILI9341 SPI LCD touchscreen, but I can't use it reliably as it also causes CPU crashes when a touchscreen interrupt is used. Again pointing to a SPI read problem.
Just know enough to get me in trouble, but not quite enough to get me out.
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 899
Posted: 11:38pm 24 Mar 2023
Copy link to clipboard 
Print this post

  HardingJohn said  
The newer STM32H743ZI2 ver V chip running at 480 MHz with ARMmite 5.07.0b1 is obviously able to handle a lot more code running before the bottleneck and crash.

John,
You say 5.07.0b1 but are you actually running 5.07.01b0, the one you initially had trouble getting to load. If so what was your fix.

Gerry
Latest F4 Latest H7
 
HardingJohn

Regular Member

Joined: 28/07/2017
Location: Australia
Posts: 78
Posted: 11:58pm 24 Mar 2023
Copy link to clipboard 
Print this post

Hi Gerry,
On boot the version is 5.07.00b11

It works fine on the newer ver V 480 MHz chip if you use a good quality crystal.
I had used some cheap ones off eBay which was a bad idea.
Stick with reputable manufacturers via Digi-Key or Mouser.
My next prototype will use an ocillator.
Just know enough to get me in trouble, but not quite enough to get me out.
 
KeepIS

Guru

Joined: 13/10/2014
Location: Australia
Posts: 1681
Posted: 08:22am 25 Mar 2023
Copy link to clipboard 
Print this post

I'm sure version listed as 5.07.00bxx are older versions (there were quite a few) and came before the release of 5.07.01b0, which I think is the latest released for the H7.

I could be incorrect ?
Edited 2023-03-25 18:22 by KeepIS
It's all too hard.
Mike.
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3816
Posted: 03:43pm 25 Mar 2023
Copy link to clipboard 
Print this post

Geoff's site has V05.07.01

I have some V05.07.02 beta versions, lastest being V5.07.02b9

John
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 899
Posted: 09:53pm 25 Mar 2023
Copy link to clipboard 
Print this post

  JohnS said  Geoff's site has V05.07.01

I have some V05.07.02 beta versions, lastest being V5.07.02b9

John


Are you talking about CMM2 here?

I am certain V5.07.01b0 is latest for ARMMite H7 code.
Edited 2023-03-26 07:55 by disco4now
Latest F4 Latest H7
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3152
Posted: 11:50pm 25 Mar 2023
Copy link to clipboard 
Print this post

TLC for ArmMite H7 (with the version number mentioned by disco4now)
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
HardingJohn

Regular Member

Joined: 28/07/2017
Location: Australia
Posts: 78
Posted: 05:19am 26 Mar 2023
Copy link to clipboard 
Print this post

Hi Gerry,
I can run V5.07.01b0 on my new prototype successfully which uses mems oscillators for both the 32.768 LSE and 8 Mhz HSE clocks (no crystals anymore) on the new Ver V chip at 480 Mhz.

The CPU lockup issue is then worse than compared to the V5.07.00b11 with me having to reduce to running 6 sockets on the Wiznet 5500 chip instead of the max of 8 so as to conserve resources, and I am now sure I have run out of Global variable memory, even though the memory command indicates plenty of RAM available for variables.

Is there a way to allocate in MMBasic more Global variables?
Just know enough to get me in trouble, but not quite enough to get me out.
 
KeepIS

Guru

Joined: 13/10/2014
Location: Australia
Posts: 1681
Posted: 06:27am 26 Mar 2023
Copy link to clipboard 
Print this post

I'm assuming you are NOT referring to H7 OPTION FLASHPAGES for code space or OPTION CONTROLS for GUI elements.
It's all too hard.
Mike.
 
HardingJohn

Regular Member

Joined: 28/07/2017
Location: Australia
Posts: 78
Posted: 11:40am 26 Mar 2023
Copy link to clipboard 
Print this post

Thanks Mike,
No, I set flash pages to 2 to allow enough room for code in flash and have removed the touchscreen as I have a GUI as a webpage that upgrades to a Websocket.
With no touch screen enabled I would think no default memory would still be allocated to GUI elements.
I am considering a prototype based on the 176 pin STM32H743IIT6 chip with the CMM2 MMbasic. I will trial it using the Wave share board first which I have a couple lying around. It would be good to have a cutdown CMM2 MMbasic with all the graphics removed as I only need raw CPU speed and max memory for SPI comms.
Just know enough to get me in trouble, but not quite enough to get me out.
 
HardingJohn

Regular Member

Joined: 28/07/2017
Location: Australia
Posts: 78
Posted: 11:52am 26 Mar 2023
Copy link to clipboard 
Print this post

I will replace all my nicely named global variables and constants with a couple of arrays. This will effectively be a Modbus Map for the whole device.
I can change their values from the Modbus terminal running in JavaScript on by webpage. As long as I keep the Modbus map up to date, I should still be able to make sense of the nameless variable coding.
Do you think this will speedup or slow down MMbasic?
Just know enough to get me in trouble, but not quite enough to get me out.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9139
Posted: 12:09pm 26 Mar 2023
Copy link to clipboard 
Print this post

The CMM2 has no more variables than the H7. Max is 512 global and 512 local at any one time
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3816
Posted: 04:12pm 26 Mar 2023
Copy link to clipboard 
Print this post

  disco4now said  
  JohnS said  Geoff's site has V05.07.01

I have some V05.07.02 beta versions, lastest being V5.07.02b9

John


Are you talking about CMM2 here?

I am certain V5.07.01b0 is latest for ARMMite H7 code.

Yes, sorry.

John
 
HardingJohn

Regular Member

Joined: 28/07/2017
Location: Australia
Posts: 78
Posted: 02:45am 27 Mar 2023
Copy link to clipboard 
Print this post

Thanks Peter,
that confirms it, I just need to replace most of my constant and global variables with arrays.  This saves me also from having to update these when a Modbus write is received as they will already be the same Modbus array. A Read Only array for constants, Read Write array for Global variables.
It will make the code very hard to understand however. A Map of the arrays identifying the purpose of each element variable in the array will need to be on hand, but will reflect fairly closely the accessible Modbus register map.

Each array element will effectively be 4 x 16 Modbus Registers and in nearly all cases be an unsigned 64 bit Integer.

Becuase all the parts of my program are heavily interactive with each other, they must share a lot of common Global variables so there are very few explicit variables.

Thanks everyone.
Just know enough to get me in trouble, but not quite enough to get me out.
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 899
Posted: 03:07am 27 Mar 2023
Copy link to clipboard 
Print this post

John,
Not sure if you use MMEdit but if you do, then the MMReplace addon to it allows you to keep your meaning full variable names and have them replaced as array elements at load time.

Option CONTROLS defaults to 200. If no GUI controls I think you could do
Option CONTROLS 0
and get a bit of memory back.(14K)
Gerry
Latest F4 Latest H7
 
HardingJohn

Regular Member

Joined: 28/07/2017
Location: Australia
Posts: 78
Posted: 11:26am 28 Mar 2023
Copy link to clipboard 
Print this post

Yes, I use MMedit.
Thanks for that.
I miss a lot of details with MMbasic as I don't have the time to follow the forum and keep up.

As Modbus is a major part of my design I still need to integrate it with most variables so that users of the device can configure it across the communications platform that it is addressing.
I may as well keep the code closely aligned with Modbus protocol by keeping everything stored in blocks of 16bit registers.

Thankyou for all your advice.
I have so much to learn.
Just know enough to get me in trouble, but not quite enough to get me out.
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024