Testing: I2C
Pre-releaseWhen sending I2C data, this program crashes with the exception...
# start_write_data
Exception Entry--->>>
mcause 30000007, mepc 23008fe2, mtval 00000014
Exception code: 7
msg: Store/AMO access fault
Here's why...
-
BL602 I2C HAL (Hardware Abstraction Layer) comes in two levels...
-
We're now using the Low Level HAL
bl_i2c.c
, because we'll be replacing FreeRTOS by Mynewt. -
According to the RISC-V Disassembly
sdk_app_i2c.S
, the MEPC (Machine Exception Program Counter)0x2300 8fe2
is located in the I2C Interrupt Handler of the BL602 I2C HAL -
Why did it crash? Because the Interrupt Context
ctx
is null!In fact, the I2C Interrupt Handler
i2c_interrupt_entry
shouldn't have been called. It comes from the High Level HALhal_i2c.c
, but we're actually using the Low Level HALbl_i2c.c
. -
Why was
i2c_interrupt_entry
set as the I2C Interrupt Handler? Becausehal_i2c_init
was called here... -
After commenting out
hal_i2c_init
, the program no longer usesi2c_interrupt_entry
as the I2C Interrupt Handler.And no more crashing!
-
But it still doesn't read the I2C sensor correctly... The result is always 0.
We generate RISC-V Disassembly sdk_app_i2c.S
from ELF Executable sdk_app_i2c.elf
with this command...
riscv-none-embed-objdump \
-t -S --demangle --line-numbers --wide \
build_out/sdk_app_i2c.elf \
>build_out/sdk_app_i2c.S \
2>&1