Я пытаюсь разобраться с работой контроллера внешней памяти в К1921ВК01Т. Использую первую альтернативную функцию портов. Разрядность шины устанавливаю 16 бит.
Код: Выделить всё
#include <stdint.h>
#include <stdbool.h>
#include <K1921VK01T.h>
#include <niietcm4.h>
#include <niietcm4_rcc.h>
#include <niietcm4_gpio.h>
#define MEM_ADDR_0 (*(volatile uint16_t *)0x40000000)
#define MEM_ADDR_1 (*(volatile uint16_t *)0x40000001)
#define MEM_ADDR_2 (*(volatile uint16_t *)0x40000002)
#define MEM_ADDR_3 (*(volatile uint16_t *)0x40000003)
#define MEM_ADDR_4 (*(volatile uint16_t *)0x40000004)
#define MEM_ADDR_8 (*(volatile uint16_t *)0x40000008)
void RCC_Initialization(void) {
RCC_PLLAutoConfig(RCC_PLLRef_XI_OSC, 100000000);
RCC_SysClkDiv2Out(DISABLE);
}
void EtxMem_Initialization(void) {
GPIO_Init_TypeDef GPIO_InitStruct;
GPIO_StructInit(&GPIO_InitStruct);
GPIO_InitStruct.GPIO_AltFunc = GPIO_AltFunc_1;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AltFunc;
GPIO_InitStruct.GPIO_Out = GPIO_Out_En;
/** A[8-15] = ADDR[0-7] */
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_8_15;
GPIO_Init(NT_GPIOA, &GPIO_InitStruct);
/** B[4-14] = ADDR[8-18] */
/** B[15] = DATA[0] */
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_4_7 | GPIO_Pin_8_15;
GPIO_Init(NT_GPIOB, &GPIO_InitStruct);
/** C[6-15] = DATA[1-10] */
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6 |
GPIO_Pin_7 |
GPIO_Pin_8_15;
GPIO_Init(NT_GPIOC, &GPIO_InitStruct);
/** D[12-15] = DATA[11-14] */
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_12_15;
GPIO_Init(NT_GPIOD, &GPIO_InitStruct);
/** E[12] = DATA[15] */
/** E[13] = MEM_WE */
/** E[14] = MEM_OE_0 */
/** E[15] = MEM_OE_1 */
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_12_15;
GPIO_Init(NT_GPIOE, &GPIO_InitStruct);
/** F[6] = MEM_CE_0 */
/** F[6] = MEM_CE_1 */
/** F[6] = MEM_LB */
/** F[6] = MEM_UB */
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;
GPIO_Init(NT_GPIOF, &GPIO_InitStruct);
/** инициализация контроллера внешней памяти */
EXTMEM_Init_TypeDef EXTMEM_InitStruct;
EXTMEM_StructInit(&EXTMEM_InitStruct);
EXTMEM_InitStruct.CEMask = EXTMEM_CEMask_Addr_19;
EXTMEM_InitStruct.EXTMEM_Width = EXTMEM_Width_16bit;
EXTMEM_InitStruct.EXTMEM_RWWaitState = EXTMEM_RWWaitState_8;
EXTMEM_InitStruct.EXTMEM_ReadWaitState = EXTMEM_ReadWaitState_8;
EXTMEM_InitStruct.EXTMEM_WriteWaitState = EXTMEM_WriteWaitState_8;
EXTMEM_Init(&EXTMEM_InitStruct);
}
int main(void) {
uint16_t delay = 0;
RCC_Initialization();
EtxMem_Initialization();
while (true) {
MEM_ADDR_3 = 0x5555;
for (delay = 0; delay < 10; delay++) ;
}
}
- Диаграмма работы | Показать