Page 1 of 2

Additional Simulator Posix HAL LLD drivers

Posted: Thu Oct 18, 2018 6:58 pm
by yusuf.husainy
Hello,

We have developed/modified a few lld drivers to use in simulator posix environment taking inspiration from STM32:
1) HAL_CAN_LLD (Uses SocketCAN)
2) HAL_SERIAL_LLD (added TTY/PTS support)
3) HAL_UART_LLD (uses TTY/PTS)
4) HAL_RTC_LLD

Also added a "simulator_registry.h" for these peripherals.

Attached a patch for these changes.

A requirement for it:

Code: Select all

#define SIMULATOR_POSIX_MCUCONF
in mcuconf.h and,

Code: Select all

#define USE_SIM_SERIAL_TTY TRUE
in mcuconf.h if intending to use TTY/PTS for HAL_SERIAL or HAL_UART.

We would highly appreciate any feedback on the work. Any suggestions are welcome. If possible we can think to include it in trunk for next release?

Re: Additional Simulator Posix HAL LLD drivers

Posted: Thu Oct 18, 2018 7:30 pm
by Giovanni
Hi,

It looks interesting, I cannot give it a try right now, too many things ongoing, I would appreciate some feedback about it.

It would help to know how to try it.

Giovanni

Re: Additional Simulator Posix HAL LLD drivers

Posted: Thu Oct 18, 2018 10:46 pm
by faisal
Giovanni wrote:Hi,

It looks interesting, I cannot give it a try right now, too many things ongoing, I would appreciate some feedback about it.

It would help to know how to try it.

Giovanni


It's pretty cool, we've been using it internally for a while now. So, it's battle tested code to some degree.

CAN: Using socket CAN allows you to connect multiple CAN nodes together (each of which could be a ChibiOS instance) on the same machine using vcan (virtual can devices - supported natively by socket CAN), or to external devices over an actual CAN device (such as a USB to CAN converter). It works transparently, and the ChibiOS application need not know if it is a virtual CAN device or a physical one. We've tested this using dozens of instances of ChibiOS running over multiple virtual CAN buses. The CAN buses were created using can-gw (in the linux can-utils package), which allows you to define routing rules between CAN devices. Using that tool, you can create multiple broadcast domains - thus making each one look like a "bus".

Serial/UART: Both of these use tty or pts in the back end. Which means, just like CAN, you can transparently have serial communication with a virtual tty device (pts) and communicate with another application on the same machine, or you can specify the path to /dev/ttyUSB0 for example - and do serial comms with a device external to the PC. The ChibiOS application doesn't really know the difference. The driver just needs a path to the device.

The UART driver is probably the one for which comments are needed. Currently it models the STM32 registers, as the existing HAL at the time didn't support character match - and we wanted our application to target both uC and simulation. This could probably use some working over...

I think improving the Simulation port of ChibiOS could lead to greater adoption as well - you don't even need hardware to evaluate it, and do quite complex things with it. For example, on each of those dozens of ChibiOS instances mentioned above, we were running a full IP stack, sensor emulation, file I/O, etc .. Each of which could be retargeted on actual hardware and pretty much "just work".

Re: Additional Simulator Posix HAL LLD drivers

Posted: Sat Oct 20, 2018 12:30 am
by yusuf.husainy
Faisal has explained the overview well. Thanks :)

I have added following example projects with README that explains usage scenarios:

1) HAL_SERIAL_LLD : $(CHIBIOS)/demos/various/RT-Posix-Simulator
2) HAL_CAN_LLD : $(CHIBIOS)/testhal/simulator/posix/CAN
3) HAL_UART_LLD : $(CHIBIOS)/testhal/simulator/posix/UART
4) HAL_RTC_LLD : TODO, will add soon.

Find these examples and the drivers in the attached updated patch.

Re: Additional Simulator Posix HAL LLD drivers

Posted: Tue Oct 23, 2018 8:32 pm
by yusuf.husainy
Hi,

I have attached the patch with HAL_RTC_LLD test example also. Please download this updated patch and experiment. It includes the drivers and the examples.

Test application locations:
1) HAL_SERIAL_LLD : $(CHIBIOS)/demos/various/RT-Posix-Simulator
2) HAL_CAN_LLD : $(CHIBIOS)/testhal/simulator/posix/CAN
3) HAL_UART_LLD : $(CHIBIOS)/testhal/simulator/posix/UART
4) HAL_RTC_LLD : $(CHIBIOS)/testhal/simulator/posix/RTC.

Re: Additional Simulator Posix HAL LLD drivers

Posted: Mon Dec 10, 2018 10:18 pm
by faisal
It seems that you're nearing a release. Would like to know if you've had a chance to check this out and consider it for inclusion in ChibiOS/HAL. Increasing the coverage of the simulator is awesome for lots of people :) - especially if the simulator can use PC peripherals to talk to the outside world (as in the case of the CAN, UART, and Serial driver that has been contributed).

Re: Additional Simulator Posix HAL LLD drivers

Posted: Tue Dec 11, 2018 8:49 am
by Giovanni
Forgot about this, too many things happening at same time...

Release is not that close anyway, I need to finalize all the changes.

Giovanni

Re: Additional Simulator Posix HAL LLD drivers

Posted: Sun Dec 16, 2018 5:46 pm
by Giovanni
Hi,

I tried this, it seems to break my testing procedures because differences in makefiles, the simulator is used for regression testing and code coverage so it is critical, in addition, coding style rules does not seem to be fully applied, I would appreciate an effort in this direction.

I will return on this at a later point.

Giovanni

Re: Additional Simulator Posix HAL LLD drivers

Posted: Mon Feb 13, 2023 8:13 pm
by faisal
Some additional drivers .. ADC, EFL, and GPT.

EFL is basically a special case of the BaseFlash simulation driver:
viewtopic.php?f=38&t=6149&p=41539#p41539

Re: Additional Simulator Posix HAL LLD drivers

Posted: Mon Mar 27, 2023 2:01 pm
by JohnyWalter3265
What are some examples of additional Simulator Posix HAL LLD drivers, and how do they enhance the functionality of the simulator?