steve-bate / ChibiOS-RPi

ChibiOS fork for Raspberry PI experimentation. See wiki for Pi-specific information.
http://chibios.org/
GNU General Public License v3.0
86 stars 23 forks source link

RPi does not respond to serial input #2

Open nmaas87 opened 11 years ago

nmaas87 commented 11 years ago

I compiled the latest version of ChibiOS-RPi with GNU ARM Embedded Toolchain (https://launchpad.net/~terry.guo/+archive/gcc-arm-embedded) on Ubuntu 12.04 JeOS and it worked. I used it with the latest RPi Firmware ( https://github.com/raspberrypi/firmware/tree/master/boot ) on an RPi Modell B 2.0 512 MB. It does flash the LED and does show the CLI, but I can't enter a command. I tried PUTTY and TerraTerm Pro on Windows 7. I used your tutorial: http://www.stevebate.net/chibios-rpi/GettingStarted.html

Note: The latest version of RPi Firmware does not use loader.bin anymore.

nmaas87 commented 11 years ago

Ok, the problem is about the RPi Firmware. With version https://github.com/raspberrypi/firmware/commit/ffbb918fd46f1b0b687a474857b370f24f71989d#boot from 06.01.2013 it does work (Serial Line and everything!)

with the Version from 07.01.2013 https://github.com/raspberrypi/firmware/tree/0ac68cce44d4550c251172e8524100090e8211fa/boot [ Enable ZRAM and RFKILL config options. … Add mutex around bcm_mailbox_property function. Fix config_hdmi_boost=4 when using hdmi_safe. ]

Serial Line broke... So seems like there would need to be made some adjustments to ChibiOS-RPi to get it working with the latest RPi Firmware...

I will stay with the 06.01.2013 for the time beeing.

steve-bate commented 10 years ago

Sorry about the delayed response. I'm not a GitHub expert but apparently I don't receive notifications for new issues. Do you have a patch I can pull?

nmaas87 commented 10 years ago

Not a problem at all. No, sorry I have no patch to pull. I just figured out this problem - but do not know how to get it back running other than using an old RPi Firmware :/! Sorry!

nmaas87 commented 10 years ago

Hey Steve, someone made an pull request on your github. Could you please accept it? Seems like someone worked on the code.

Nico

2013/8/6 steve-bate notifications@github.com

Sorry about the delayed response. I'm not a GitHub expert but apparently I don't receive notifications for new issues. Do you have a patch I can pull?

— Reply to this email directly or view it on GitHubhttps://github.com/steve-bate/ChibiOS-RPi/issues/2#issuecomment-22211483 .

z08840 commented 10 years ago

I made it work finally. Have not checked yet which code doesn't work in original version. My correction for os/hal/platforms/BCM2835/serial_lld.c

void sd_lld_start(SerialDriver *sdp, const SerialConfig *config) {
  UNUSED(sdp);

  if (config == NULL)
    config = &default_config;

  IRQ_DISABLE1 = BIT(29);

  AUX_ENABLES = 1;

  AUX_MU_CNTL_REG = 0x00;    // disable tx and rx (+set other control bits to default)
  AUX_MU_IER_REG  &= ~0x03;  // disable rx tx interrupts
  AUX_MU_LCR_REG  |= 0x03;   // 8-bit mode
  AUX_MU_MCR_REG  = 0x00;    // set RTS high (default)
  AUX_MU_BAUD_REG = BAUD_RATE_COUNT(config->baud_rate);

  bcm2835_gpio_fnsel(14, GPFN_ALT5);
  bcm2835_gpio_fnsel(15, GPFN_ALT5);

  GPPUD = 0;
  bcm2835_delay(150);
  GPPUDCLK0 = (1<<14)|(1<<15);
  bcm2835_delay(150);
  GPPUDCLK0 = 0;

  AUX_MU_IER_REG |= 0x03;  // enable rx tx interrupts
  AUX_MU_IIR_REG |= 0x06;  // clear FIFOs
  AUX_MU_CNTL_REG = 0x03;  // enable tx and rx (+set other control bits to default)

  IRQ_ENABLE1 = BIT(29);
}
nmaas87 commented 10 years ago

Perfect! I can confirm that it works now with the latest firmware. ( bootcode.bin and start.elf from here: https://github.com/raspberrypi/firmware/tree/master/boot - Version 97082b6e95a2792660c2f79389748beccdbc568e as from 6 days ago )

Thanks a lot, z08840! You should check in your change as Pull Request.

z08840 commented 10 years ago

The peripherals pdf (http://www.raspberrypi.org/wp-content/uploads/2012/02/BCM2835-ARM-Peripherals.pdf) is full of errors - errata can be found here: http://elinux.org/BCM2835_datasheet_errata

I figured out that only next change is sufficient to make original code work:

AUX_MU_IER_REG  = 0x00;

to

AUX_MU_IER_REG  &= ~0x03;

However, some values in original code seems don't make much sense and looks erroneous to me. Also I see as a bad practice to use '=' instead of 'bit set/clear' - although I don't see any direct asm command for such operation (my knowledge of arm asm is very basic), and I think there is no any - compiler translates '|=' and '&= ~' into "load data into register, switch necessary bits, store register to the original location' - which makes perfect sense (I implemented this operation same way before). The second issue in original code - the sequence of operations doesn't look meaningful for me - in my version I organized it to prevent any garbage to appear on UART during transitional processes and looks like it behaves much better.

However I'm not proficient in programming MCU in general, and for this particular architecture it was mostly my first code, so I'm not sure it's absolutely correct and prefer to left it for some more experienced maintainer to fix it if necessary and merge to trunk.