Event logging in Embedded Systems
Normally, in SBC running RTOS, it would be an easy task to write data/event logs onto an external media such as SD cards. However, in embedded systems that uses microcontroller, e.g. PIC microchips, have limited data/program memory. Although some chipset have the support for external media, assumming that it doesn't, how would one log in MCU?
The only plausible way that I could think of is to write it to MCU's EEPROM, b开发者_如何学Gout is this feasible? If this could be done, how would one write and read?
Logging can be performed to any memory device, SD cards included (assuming the relevant hardware peripheral is available). If there is an external device attached over a serial port, you can write data to it.
Commonly, event logging is done in exceptional cases only. Writing to EEPROM or Flash (for newer devices) is relatively slow, consumes power, and uses up a finite resource (space, and erase cycles).
For debugging, using a serial port (or the SWO port on Cortex-M3) is common.
You can implement a logging facility which simply writes a byte into an array each time you want to log an event. The log list can then be retrieved and converted to a human readable list of events. This approach has the benefit to be less intrusive for real-time applications.
I used this approach for an application where 100-200 events were generated in a 1-2 minute test session. The list was then downloaded over a serial port and analyzed with a little Python script.
Depending on your data needs, you could either go for a SPI flash or an I²C EEPROM.
I2C EEPROMS are smaller in terms of storage but its interface is available in most microcontrollers (if not, it is relatively easy to do it in software with regular IO pins) and they are a lot slower (mainly because of the I2C bus that is limited at 1Mhz). It is easy to find them up to 1mbit in capacity and with 8DIP packaging.
SPI flashes are faster, with higher density and often cheaper, so if you need fast writes and, to be honest, better technology you should go for them.
One would normally output the data to a UART and capture, or display it in a terminal emulator such as TeraTerm (or HyperTerminal if you must).
If you implement a ring-buffer and ISR to feed the UART there will be minimal impact on the run-time behaviour of the system so long as you do not exceed the data throughput capability of the port for sustained periods. It is likley to have lower system impact and be more deterministic than writing to EEPROM or Flash, especially if the UART has FIFO or DMA capabilities, and while bandwidth may be limited, it has the advantage of practically limitless capacity.
Your chip may have on-chip debug capabilities that might be coupled with a host debugger with arbitrary debug output or semi-hosting capability. This would have minimal run-time impact.
精彩评论