大家好,我的環(huán)境是VSCode+PlatformIO+OpenOCD,在搭建ch32v的開(kāi)發(fā)環(huán)境,目前能夠編譯和燒寫(xiě)代碼,代碼燒錄后的運(yùn)行情況和預(yù)期不同,試圖進(jìn)行調(diào)試,該過(guò)程中出現(xiàn)如下問(wèn)題:
完成GPIO配置后,main函數(shù)里有下述語(yǔ)句:
GPIOD->OUTDR?|=?GPIO_Pin_3; GPIOD->OUTDR?&=?~GPIO_Pin_3; GPIOD->OUTDR?|=?GPIO_Pin_3; GPIOD->OUTDR?&=?~GPIO_Pin_3; GPIOD->OUTDR?|=?GPIO_Pin_3; GPIOD->OUTDR?&=?~GPIO_Pin_3;
當(dāng)進(jìn)行單步調(diào)試時(shí),隨著逐語(yǔ)句執(zhí)行,開(kāi)發(fā)板上與PD3相連的LED按照預(yù)期亮和滅。但是一旦加入一些最簡(jiǎn)單的延時(shí)代碼后:
void?delay(uint32_t?val) { ????for?(int?i?=?val;?i?>?0;?--i) ????{ ????????volatile?int?j?=?1000; ????????while?(--j); ????} } int?main() { ????//?...?GPIO?clock?enable?and?initialization ???? ????while?(1) ????{ ????????GPIOD->OUTDR?|=?GPIO_Pin_3; ????????delay(1000); ????????GPIOD->OUTDR?&=?~GPIO_Pin_3; ????????delay(1000); ????} ????return?0; }
編譯燒錄后PD3的LED表現(xiàn)為常亮,當(dāng)開(kāi)啟調(diào)試模式,執(zhí)行到delay(1000)這一行并試圖step over的時(shí)候,CPU似乎進(jìn)入了復(fù)位,LED熄滅,調(diào)試終端持續(xù)打?。?/p>
Info : [wch_riscv.cpu.0] Hart unexpectedly reset!
[wch_riscv.cpu.0] Hart unexpectedly reset!
Info : [wch_riscv.cpu.0] Hart unexpectedly reset!
[wch_riscv.cpu.0] Hart unexpectedly reset!
Info : [wch_riscv.cpu.0] Hart unexpectedly reset!
[wch_riscv.cpu.0] Hart unexpectedly reset!
......
然而將上述代碼while(1)中的兩行GPIO賦值語(yǔ)句順序顛倒后(即先關(guān)閉LED, 延時(shí),再打開(kāi)LED),燒錄運(yùn)行后表現(xiàn)為L(zhǎng)ED不亮。
請(qǐng)問(wèn)上述調(diào)試報(bào)錯(cuò)表示哪里出現(xiàn)了問(wèn)題?該現(xiàn)象是否是說(shuō)明代碼一旦執(zhí)行到某個(gè)函數(shù)調(diào)用,就會(huì)自己崩掉?