Heat the oil in a large skillet. Add the onion and sauté until translucent. Add the garlic and bell pepper and continue to sauté until the onion is golden brown.
Add the corn kernels, pinto beans, tomatoes, and seasonings. Stir well and simmer for 10 to 15 minutes. Season to taste with salt. Remove from the heat.
Bring 5 cups of water to a rolling boil in a heavy saucepan or double boiler. Slowly pour the cornmeal into the water in a thin, steady stream, stirring continuously to avoid lumping. Add the salt and cook over very low heat, covered, for 20 minutes, stirring occasionally.
Preheat the oven to 375°F
Oil a shallow, 1 1/2-quart baking dish and line the bottom with half of the cooked cornmeal. Pour over it the skillet mixture and sprinkle with the optional grated cheese. Top with the remaining cornmeal, patting it in smoothly.
Bake for 45 to 50 minutes, or until the cornmeal is golden brown and crusty. Let stand for 10 minutes, then cut into squares to serve.