我尝试为一个非常小的引导加载程序编写一个函数。哪个应该向显示器发送命令。
然而,最后一条语句“LPSPI0->TDR = (uint32_t)(0x20<<8);” 造成硬故障,我不知道为什么。谁能帮我?MCU 是 K32L2A31A。
__attribute__ ((naked, sec
tion(".after_vectors.reset")))
void showBLMInfo(void){
//Connect CMP1 with TPM2
TRGMUX_TPM2 = TRGMUX_TRGCFG_SEL0(0b100111);
//Comparator for regulated Chargepump
PCC_CMP1 = PCC_CLKCFG_CGC_MASK; //Clock enable
//Caution Vin2 as reference is VDD, datasheet is wrong here!
CMP1->DACCR = CMP_DACCR_DACEN_MASK | CMP_DACCR_VRSEL_MASK | CMP_DACCR_VOSEL(0x2E);
CMP1->MUXCR = CMP_MUXCR_MSEL(7) | CMP_MUXCR_PSEL(0);
CMP1->CR1 = CMP_CR1_EN_MASK;
//Generate PWM for Chargepump
PCC_TPM2 = PCC_CLKCFG_CGC_MASK | PCC_CLKCFG_PCS(2); //Clock enable, Fast IRC
TPM2->CONF = TPM_CONF_CPOT_MASK | TPM_CONF_TRGSEL(0) | TPM_CONF_DBGMODE_MASK;
TPM2->CNT = 0;
TPM2->MOD = 10;
TPM2->CONTROLS[1].CnSC = TPM_CnSC_ELSB_MASK | TPM_CnSC_MSB_MASK;
TPM2->CONTROLS[1].CnV = 5;
//Enable Chargepump
TPM2->SC = TPM_SC_CMOD(1) | TPM_SC_PS(2);
//GPIO
//GPIO_SPI0_CS_DISP_GPIO->PCOR = GPIO_SPI0_CS_DISP_GPIO_PIN_MASK;
//EN_U_BAT, EN_DISP
PCC_PORTE = PCC_CLKCFG_CGC_MASK; //Clock enable PORT E
PCC_PORTD = PCC_CLKCFG_CGC_MASK; //Clock enable PORT D
PORTE->PCR[1] = PORT_PCR_MUX(1); //EN_U_BAT
PORTE->PCR[25] = PORT_PCR_MUX(2); //EN_DISP
PORTD->PCR[0] = PORT_PCR_MUX(2); //CS
PORTD->PCR[1] = PORT_PCR_MUX(2); //SCK
PORTD->PCR[2] = PORT_PCR_MUX(2); //MOSI
GPIOE->PDDR = (1U << 25U) | (1U << 1U);
GPIOE->PSOR = (1U << 25U) | (1U << 1U);
//1Hz Refresh Clock
//RTC->CR |= RTC_CR_CPE(1);
PCC_LPSPI0 = PCC_CLKCFG_CGC_MASK | PCC_CLKCFG_PCS(2); //Clock enable
LPSPI0->CR = LPSPI_CR_DBGEN_MASK | LPSPI_CR_MEN_MASK;
LPSPI0->CFGR1 = LPSPI_CFGR1_MASTER_MASK | LPSPI_CFGR1_PCSPOL(1) | LPSPI_CFGR1_AUTOPCS_MASK;
LPSPI0->CCR = LPSPI_CCR_PCSSCK(11)|LPSPI_CCR_SCKPCS(2)|LPSPI_CCR_DBT(4);
//Send Display clear command
LPSPI0->TCR = LPSPI_TCR_FRAMESZ(15) | LPSPI_TCR_PRESCALE(4) | LPSPI_TCR_TXMSK_MASK | LPSPI_TCR_CONT_MASK; //16bit Transfer
LPSPI0->TDR = (uint32_t)(0x20<<8);
}
非常感谢。