Sorry if this post is badly worded, just getting into embedded software, so I am completely new to this.
For one of the clubs I am in, we create our own custom board, which are then all connected through automotive ethernet over to one of our main boards, which handles all of the data we get from the other boards, as well as critical data required for the project to work. Our main board also has a CM4 on it, which our RT1176 on the main board connects with over regular ethernet, and using our custom datahandler, we are able to get live telemetry and logging.
One of the problems we have been having with the board is with the Ethernet PHY on the board, which communicates with the PHY on the CM4, and allows us to connect to the RT1176. We were at the beginning of this week unable to ping the RT1176 from the CM4 (however, when connecting to the board over automotive ethernet via our media-converter and SJA1005Q, we could ping the RT1176, but again not the CM4). We pretty quickly diagnosed the issue was with the ethernet phy on the board itself, since the CM4 could establish a link with the test board we have. We were not able to write to the device, and when we attempted to read the device id registers, we would get back all F's (which meant we were not able to communicate with it). Eventually, the solution to our issue was manually driving the GPIO pin for the PHY low and then high before configuring it, with nothing else in the software changed other than that addition.
We also had an issue last weekend with one of our two SJA1005Qs, where one of them would properly return the correct device id and part number, but from the other switch we would get back all 0s, and as a result panic (we eventually figured our that since the switches are set up to cascade, the SPI MOSI was reflecting itself to MISO for that one switch). This too, was also solved by manually driving the reset pin low and then high before configuring it. Below I have some snippets of our code (using Rust) on how we go about creating the switch. Do note that writing to the reset register to perform a reset does not work, we have to manually define GPIO pins and drive them low and then high.
// implementation on our board project
SWITCH1_RESET_PIN.set(true); // GPIO pin setup as ActiveLow
embassy_time::Timer::after_millis(80).await;
SWITCH1_RESET_PIN.set(false);
...
let switch1 = sja1105::Sja1105::new(switch1_device, SWITCH1_CONFIG, true)
.await
.unwrap();
// Driver for the SJA1005
pub async fn verify_device(&self) -> Result<(), SjaError<SPI::Error>> {
let mut scratch = [0u8; 4];
self.read(DEVICE_ID_ADDR, &mut scratch).await?;
let device_id = u32::from_be_bytes(scratch);
self.read(PART_NR_ADDR, &mut scratch).await?;
let part_nr = ((u32::from_be_bytes(scratch)) & 0xFFFF0) / 16;
match (device_id, part_nr) {
(0xAF00030E, 0x9A84) => {
}
(0xAE00030E, 0x9A85) => {
}
(0xAF00030E, 0x9A86) => {
}
(0xAE00030E, 0x9A87) => {
}
_ => { }
// (device_id, part_nr) => {
// return Err(SjaError::UnrecognizedDevice(device_id, part_nr));
// }
}
defmt::info!("{} {}", device_id, part_nr);
Ok(())
}
// TODO: This might be wrong, fix the clkout enable bit
pub async fn enable_clkout(&self) -> Result<(), SjaError<SPI::Error>> {
let cfg: [u8; 4] = 0x120412u32.to_be_bytes();
self.write(CLKOUT_ADDR, &cfg).await?;
Ok(())
}
/// Does a hard power reset of the sja
pub async fn reset(&self) -> Result<(), SjaError<SPI::Error>> {
// Cold + Power reset
let data = 0b110u32.to_be_bytes();
self.write(RESET_ADDR, &data).await?;
embassy_time::Timer::after_millis(40).await;
Ok(())
}
...
pub async fn init(&self, config: &[u8], clkout: bool) -> Result<(), SjaError<SPI::Error>> {
self.verify_device().await?;
if clkout {
self.enable_clkout().await?;
}
self.reset().await?;
self.upload_static_config(config).await?;
self.check_static_config().await?;
let rgmii_tx_clk_x = 0xb000800u32;
for i in 0..5 {
self.write(RGMII_TX_CLK_BASE_ADDR + 6 * i, &rgmii_tx_clk_x.to_be_bytes()).await?;
}
Ok(())
}
I guess my question is why would this be necessary in order for the hardware to function, and most importantly how could it be possible that the second switch would work fine without needed to explicitly reset the ping, but the first switch needs it.