RC15 Serial & GPIO
Terry Swanborough (61) 152 posts |
Hi I have a program that uses GPIO and serial connections at the moment I use the modules:- The device I’m using is connected on the serial connection it waits for a single ASCII byte G to V Anyway if I use the OS_SerialOp commands in RC15 I cannot receive any characters from As I can send the correct byte to the unit I am assuming that the format and baud rate I am using:- SYS “OS_SerialOp”,3,byte for TX in receive byte% is always 0 GPIO seems to operate correctly BTW if I try Anyone else using serial receive? Terry |
Chris Hall (132) 3554 posts |
I use the following:
r1% is preserved if nothing received but 0 is a valid serial byte to receive. I also use
Pin BCM 14 (TXDATA) should return mode 5 (UART) – are you using GPIO 1.00 as GPIO 0.60 returns 4 (ALT0) or 5 (ALT 1) here. |
Terry Swanborough (61) 152 posts |
If I boot up a fresh RC15 with GPIO 1.00 loaded Also I still can’t get any characters to receive using your code above Terry |
Chris Hall (132) 3554 posts |
The Serial module is now in ROM so you should not load the serial block drivers !SerialDev (it is now obsolete) – if you load the block drivers (PiSerial_xxx SWIs) as well as the Serial module in ROM (OS_Serial SWIs) you won’t receive anything. |
Terry Swanborough (61) 152 posts |
Hi Chris I am not loading Piserial I am only using I loaded PIserial later to try to test the serial connections Terry |
Chris Hall (132) 3554 posts |
What have you connected to the RXDATA pin? Are you receiving any characters, top bit set for example. Could be wrong speed setting. |
Terry Swanborough (61) 152 posts |
Hi I have a PIC device connected to the RX pin that waits for a character on its receive pin and then responds on its TX pin. Connected between this and the raspberry pi is an rs232 voltage translator chip I realise that the pi runs at 3v3. Anyway all this must be working because if I take a version of the software using piserial it all works OK. I am obviously not setting up something correctly but I can’t see what? I have set the rx and tx speeds and can tx to the device. On Tuesday I will set up a PC to stream out characters and connect that? Thanks for your help if you have rx working on RC15 then it’s got to be my setup. |
Terry Swanborough (61) 152 posts |
Hi The below maybe of use to others? I have now got serial working with RC15. In this situation you normally use a master (Raspberry PI) and slaves (in my case PIC chips) Anyway my original PIserial transmit routine was. DEFFNSerial_TX_Byte(byte%) This works OK DEFFNSerial_TX_Byte(byte%) PROCGPIO_RS485_TX_Enable :REM enable output SYS"OS_SerialOp",3,byte% REPEAT SYS "OS_Hardware",0,0,0,0,0,0,0,0,0,71 TO out% UNTIL (out% AND 64)=64 PROCGPIO_RS485_TX_Disable :REM Disable output =TRUE I have to add the OS_Hardware command to ensure that the transmission is complete before I start receiving data from the slaves. |
Timo Hartong (2817) 1 post |
I have downloaded the source for the raspberry pi and I’m now trying to compile. It looks that only for one serial port something is done . The HAL entry HAL_UARTPorts only gives one port back. ( It is there in the code ). How is the opinion here should the second serial port also be supported ? And how ?. I want to give it a go to code it. |
Jeffrey Lee (213) 6048 posts |
As I understand it the second serial port (the “mini UART”) derives its clock from the CPU clock. So any time the CPU frequency changes the UART will need to be reconfigured. The OS will adjust the CPU clock to try and save on power when the system is idle. So we could extend the OS to allow the UART driver to be aware of those transitions and either prevent them from happening or re-adjust itself accordingly. But the GPU can also decide to adjust the CPU clock itself (e.g. to stop the system overheating), and I don’t think it directly notifies us when that happens. So unless the CPU is locked at the slowest frequency the mini UART is always going to be a bit unstable. If you want to try writing a driver for the mini UART, I think you have three options available:
The mini UART is described in the public BCM2835 datasheet, this page has a link to it and a bunch of document errata. However, if you’re interested in getting the Pi 3’s bluetooth chip working, it might be better to go with the approach Linux uses: Use the PL011 UART for bluetooth and use the mini UART for the debug/serial terminal. HAL_UARTStartUp adjusts the pin mux settings so that the PL011, you should be able to adjust (or just disable) that code so that it uses the right pin mux settings for the bluetooth chip. You may also want to delete lines 273-278 inclusive so that higher UART transfer rates can be used (note that this will also break the clock divider calculation, since UARTCLK is hardwired to 3MHz). IIRC, apart from having a higher clock rate and not being affected by the CPU clock rate, the PL011 also has deeper FIFOs than the mini UART, so it’s definitely the best choice when you want performance & reliability. |
Timo Hartong (2813) 204 posts |
Yes, I want to get the Bluetooth chip working I think that is a little bit less complicated than the WiFi part of the CYW43438 . The CYW43438 is if I have read the documentation correctly connected to the PL011 but I want to have the mini UART also working. |
Jeffrey Lee (213) 6048 posts |
Putting it in the HAL would be more consistent with other platforms. In theory it should also be the simplest way of getting it up and running, since you won’t need to worry about writing your own DeviceFS interface (the Serial module automatically populates DeviceFS with devices for all of the HAL UARTs) However, placing it in the HAL will make it difficult to deal with the CPU clock changes: One of the design goals of the HAL is to make it OS-agnostic, so you can’t really have the HAL call arbitrary RISC OS SWIs in order to monitor the CPU speed. If you want to implement it within the HAL, perhaps the cleanest option would be to have the HAL export a new HAL device containing whatever entry points are necessary to allow the UART driver to be notified of clock changes. Then the BCMSupport module can detect that device and call it whenever it’s changing the CPU speed.
Yes. You can use C in the HAL, but any library functions you need will have to be implemented yourself. |
Timo Hartong (2813) 204 posts |
Thank you for this elaborate answer. I will think about it how I can do this best but it can take some time ;-). You work and earning money. So I will go for the HAL route and conform to the ‘rules’. |
Timo Hartong (2813) 204 posts |
Hi Mainwhile I made some progress and I’m now writing the miniUART driver in C with already preparing to be put in the HAL. Sorry for the delay but the problem with work it consumes so much free time. |
Steffen Huber (91) 1953 posts |
I dimly remember that there was a time when “ansilib” was available in addition to “SharedCLib” which allowed for a “standalone” approach. Is this still available and/or sensible? |
Jeffrey Lee (213) 6048 posts |
Available: Yes Sensible: No (although a stripped-down ANSILib which just provides OS-independent things like strcmp, sprintf, etc. might make sense) |
Rick Murray (539) 13840 posts |
The last time I looked (C v4), ansilib was a rather “all or nothing” library, in that you either linked all or most of it, or nothing. It’s a shame Acorn never bothered to implement their libraries properly so you only needed to link in the functions actually used (and their dependencies) and not huge swathes of unnecessary code “because it is in the same source file”… |
RonM (387) 60 posts |
The last time I looked (C v4), ansilib was a rather “all or nothing” library, in that you either linked all or most of it, or nothing. I came across a possible need for strlcpy, and I found there is a libbsd maintained for GNU linux primarily, I think. It is intended to link as a whole, but to use a single function, it could be taken out of it’s C file and used. The include files look like they would exist as include/bsd/string.h etc, but once again, you could probably have a local src declaration header like “bsd.h”. |
Timo Hartong (2813) 204 posts |
Hmm ansers about C very nice indeed. But I wanted to know something about interrupt numbers. |
Jeffrey Lee (213) 6048 posts |
Good point!
If the code is in the HAL (implementing the HAL UART API), then the Serial module (aka the DualSerial component in CVS) which will be in charge of registering & implementing the interrupt handler (making use of the appropriate HAL UART calls, e.g. HAL_UARTInterruptID to determine the cause of the interrupt) If you’re implementing a prototype outside of the HAL, you’ll have to register & implement the interrupt handler manually (using OS_ClaimDeviceVector to register the handler with the OS, followed by HAL_IRQEnable to make sure the interrupt isn’t masked in the interrupt controller) – and if you’re using C then this would ideally be done in a module, so that CMHG veneers can be used to allow your C code to be called by the kernel (since the kernel doesn’t know how to set up the C environment your code needs). Or you could conceivably test the code by polling the interrupt register (i.e. whenever you’re expecting an interrupt, call your HAL_UARTInterruptID implementation in a loop until it says something’s happening)
I believe it will be 29, aka iDev_GPU_AuxInt from hdr.BCM2835 in the HAL sources. But because it’s a shared interrupt (shared with two of the SPI busses) you’ll also have to set bit 31 so that OS_ClaimDeviceVector knows to treat it as a shared interrupt (but when you call e.g. HAL_IRQEnable, bit 31 must be masked out!). You’ll also have to interact with the AUXEnables and AUXIRQ registers (similar to the SPI code) to enable/disable and check for the UART interrupt. |
Timo Hartong (2813) 204 posts |
Another question I have made a C header file ( I’m writing the drivers in C instead of assembler ) would it be desirable to have the same names as in in the hdr.BCM2835 or will this lead to a clash ?. |
Timo Hartong (2813) 204 posts |
A small update I’m now able to send karakters. See for a oscilloscope picture : https://www.riscosopen.org/forum/forums/2/topics/9265 _ |